Skip to content
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

Merged
merged 15 commits into from Mar 23, 2021
Merged

Conversation

Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants
@algobytewise
Copy link
Contributor

@algobytewise algobytewise commented Mar 23, 2021

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

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Documentation change?

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation.
  • If this pull request resolves one or more open issues then the commit message contains Fixes: #{$ISSUE_NO}.
.github/workflows/build.yml Outdated Show resolved Hide resolved
@@ -13,7 +13,7 @@
print("Receiving data...")
while True:
data = sock.recv(1024)
print(f"data={data}")
print(f"data={str(data)}")
Copy link
Member

@cclauss cclauss Mar 23, 2021

Why this change?

Suggested change
print(f"data={str(data)}")
print(f"{data = }")

Copy link
Member

@dhruvmanila dhruvmanila Mar 23, 2021

This and similar changes are redundant as string interpolation converts the object to string using the __str__ method of the object.

Copy link
Contributor Author

@algobytewise algobytewise Mar 23, 2021

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

Copy link
Contributor Author

@algobytewise algobytewise Mar 23, 2021

I guess it has something to do with the method from the socket-package that returns the data-object.

Copy link
Member

@cclauss cclauss Mar 23, 2021

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
Copy link
Member

@cclauss cclauss Mar 23, 2021

@dhruvmanila Do we need these imports for basic types in Python 3.9 and the current mypy?

Copy link
Member

@dhruvmanila dhruvmanila Mar 23, 2021

No, I updated the issue with the message: #4052 (comment)

Copy link
Contributor Author

@algobytewise algobytewise Mar 23, 2021

I see, I made the corresponding changes. One difference is that the basic types are spelled lower case without this import.

@@ -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)}")
Copy link
Member

@cclauss cclauss Mar 23, 2021

Suggested change
print(f"Server received {str(data)}")
print(f"Server received: {data = }")

Copy link
Member

@cclauss cclauss left a comment

LGTM...

@cclauss cclauss merged commit 9595079 into TheAlgorithms:master Mar 23, 2021
2 checks passed
@algobytewise algobytewise deleted the mypy-fix-small-folders branch Mar 23, 2021
peRFectBeliever added a commit to peRFectBeliever/Python that referenced this issue Apr 1, 2021
* 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>
Panquesito7 pushed a commit to Panquesito7/Python that referenced this issue May 13, 2021
* 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>
shermanhui added a commit to shermanhui/Python that referenced this issue Oct 22, 2021
* 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment