[mypy] fix small folders #4292
[mypy] fix small folders #4292
Conversation
…ise/Python into mypy-fix-small-folders
@@ -13,7 +13,7 @@ | |||
print("Receiving data...") | |||
while True: | |||
data = sock.recv(1024) | |||
print(f"data={data}") | |||
print(f"data={str(data)}") |
cclauss
Mar 23, 2021
•
Member
Why this change?
print(f"data={str(data)}") | |
print(f"{data = }") |
dhruvmanila
Mar 23, 2021
Member
This and similar changes are redundant as string interpolation converts the object to string using the __str__
method of the object.
algobytewise
Mar 23, 2021
Author
Contributor
I'm not sure why but without it we get the following mypy-errors:
file_transfer/send_file.py:16: error: On Python 3 '{}'.format(b'abc') produces "b'abc'", not 'abc'; use '{!r}'.format(b'abc') if this is desired behavior
file_transfer/receive_file.py:16: error: On Python 3 '{}'.format(b'abc') produces "b'abc'", not 'abc'; use '{!r}'.format(b'abc') if this is desired behavior
algobytewise
Mar 23, 2021
Author
Contributor
I guess it has something to do with the method from the socket-package that returns the data-object.
cclauss
Mar 23, 2021
Member
bytes
vs. str
is the most time-consuming part of porting code from Python 2 to Python 3.
% python3
>>> type(b"abc")
<class 'bytes'>
>>> type("abc")
<class 'str'>
@@ -1,7 +1,7 @@ | |||
from typing import List | |||
from typing import List, Tuple |
cclauss
Mar 23, 2021
Member
@dhruvmanila Do we need these imports for basic types in Python 3.9 and the current mypy?
algobytewise
Mar 23, 2021
•
Author
Contributor
I see, I made the corresponding changes. One difference is that the basic types are spelled lower case without this import.
This reverts commit 2f7c473.
@@ -13,7 +13,7 @@ def send_file(filename: str = "mytext.txt", testing: bool = False) -> None: | |||
conn, addr = sock.accept() # Establish connection with client. | |||
print(f"Got connection from {addr}") | |||
data = conn.recv(1024) | |||
print(f"Server received {data}") | |||
print(f"Server received {str(data)}") |
cclauss
Mar 23, 2021
Member
print(f"Server received {str(data)}") | |
print(f"Server received: {data = }") |
LGTM... |
* add final else-statement * fix file_transfer * fix quantum folder * fix divide_and_conquer-folder * Update build.yml * updating DIRECTORY.md * Update ripple_adder_classic.py * Update .github/workflows/build.yml * removed imports from typing * removed conversion to string * Revert "removed conversion to string" This reverts commit 2f7c473. * implemented suggested changes * Update receive_file.py Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Co-authored-by: Christian Clauss <cclauss@me.com>
* add final else-statement * fix file_transfer * fix quantum folder * fix divide_and_conquer-folder * Update build.yml * updating DIRECTORY.md * Update ripple_adder_classic.py * Update .github/workflows/build.yml * removed imports from typing * removed conversion to string * Revert "removed conversion to string" This reverts commit 2f7c473. * implemented suggested changes * Update receive_file.py Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Co-authored-by: Christian Clauss <cclauss@me.com>
Describe your change:
Related Issue: #4052
comment for strassen_matrix_multiplication.py: I couldn't use Tuple as return type since one branch of the function returns a tuple an another a list/matrix. So I turned the tuple into a list instead.
comment for electric_power.py & ohms_law.py: I added a final else-clause for raising an error to make sure that each branch either has a return-value or throws an error
Checklist:
Fixes: #{$ISSUE_NO}
.