TheAlgorithms / Python Public
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[mypy] fix small folders #4292
[mypy] fix small folders #4292
Conversation
…ise/Python into mypy-fix-small-folders
file_transfer/receive_file.py
Outdated
@@ -13,7 +13,7 @@ | |||
print("Receiving data...") | |||
while True: | |||
data = sock.recv(1024) | |||
print(f"data={data}") | |||
print(f"data={str(data)}") |
Why this change?
print(f"data={str(data)}") | |
print(f"{data = }") |
This and similar changes are redundant as string interpolation converts the object to string using the __str__
method of the object.
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
I guess it has something to do with the method from the socket-package that returns the data-object.
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 |
@dhruvmanila Do we need these imports for basic types in Python 3.9 and the current mypy?
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.
file_transfer/send_file.py
Outdated
@@ -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)}") |
print(f"Server received {str(data)}") | |
print(f"Server received: {data = }") |
* 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>
* 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}
.The text was updated successfully, but these errors were encountered: