Skip to content

[mypy] fix small folders #4292

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

Merged
merged 15 commits into from
Mar 23, 2021

Conversation

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}.

@ghost ghost added enhancement This PR modified some existing files awaiting reviews This PR is ready to be reviewed labels Mar 23, 2021
@ghost ghost added tests are failing Do not merge until tests pass and removed tests are failing Do not merge until tests pass labels Mar 23, 2021
@@ -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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this change?

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor Author

@algobytewise algobytewise Mar 23, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@ghost ghost added the tests are failing Do not merge until tests pass label Mar 23, 2021
@ghost ghost removed the tests are failing Do not merge until tests pass label Mar 23, 2021
@@ -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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Member

@cclauss cclauss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM...

@ghost ghost removed the awaiting reviews This PR is ready to be reviewed label Mar 23, 2021
@cclauss cclauss merged commit 9595079 into TheAlgorithms:master Mar 23, 2021
@algobytewise algobytewise deleted the mypy-fix-small-folders branch March 23, 2021 15:54
peRFectBeliever pushed a commit to peRFectBeliever/Python that referenced this pull request 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 <[email protected]>
Panquesito7 pushed a commit to Panquesito7/Python that referenced this pull request 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 <[email protected]>
shermanhui pushed a commit to shermanhui/Python that referenced this pull request 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 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement This PR modified some existing files
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants