-
-
Notifications
You must be signed in to change notification settings - Fork 122
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
Type annotation implementation #203
base: main
Are you sure you want to change the base?
Conversation
Fix bugs with wildcard imports Use context manager for file reading in `setup.py` Update tox.ini Update license copyright years
Add module `types.py` with custom types Add type annotations to geojson functions Refactor some functions Update functions docstrings
Hello @NoharaMasato! Thank you for you reply.
|
I don't use this package often, but I took a cursory look and it looks great. |
|
||
# Python 3.7 doesn't support using isinstance() with Protocols | ||
# Use checks for (Real, Decimal) instead | ||
SupportsRound: TypeAlias = Union[Real, Decimal] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello, thank you for your comment. It's been a while since I suggested this PR, but if I remember correctly, I considered the possibility of using Number
instead of the Real
-Decimal
combination. Please correct me if I am wrong, but as I understand, some members of the Number subset do not support the SupportsRound
protocol (for example, Complex). So, it is impossible to use them in this case.
The best solution is to use the SupportsRound
protocol from the typing
library, but it is only possible in the case of dropping support for Python 3.7.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reopening this as a reminder to implement typing.SupportsRound
here as part of dropping Python 3.7 support.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, to be clear, @am1ter, please use Number
as per #188 as @trcmohitmandokhot suggested. Let's not worry about the edge case of complex numbers to whatever extent that might still be a factor.
@am1ter - Thank you for the commit. My apologies for getting to this so late. I am very new to implemting Typing in Python, but overall the types.py feels good to me. I will review it some more and ask a few questions! This looks like an impressive and comprehensive effort! |
@trcmohitmandokhot Thank you for the review. By the way, the changes in this PR are so huge, a review from @rayrrr as the maintainer of this repository is mandatory. |
@am1ter thank you for your efforts here, and apologies for the delayed review. It was your statement in the description...
..which gave me pause. Which features? Notably, in the intervening time since you originally submitted this PR, Python 3.7 has been EOL'ed. I propose that we drop 3.7 support as part of this type annotation implementation, and implement whatever features were blocked. @am1ter would you be able to handle that? |
I am trying to connect the dots and answer @rayrrr 's question "which features cannot be implemented" if Python 3.7 compatibility is to be retained. My read of the situation is that two things change on the typing library between Python 3.7 and 3.8.
|
Hello @rayrrr, @trcmohitmandokhot. Thank you for your responses here. I've had a very busy two weeks, so I apologize for the late response. Regarding your question about type-related features that Python 3.7 doesn't support, @trcmohitmandokhot's response is correct. As I recall, I mentioned in my description what bothered me in Python 3.7 limitations: Python 3.7 doesn't support using the @rayrrr, if you like the main idea of this PR and approve of dropping Python 3.7 support, I believe I can update the PR accordingly and update resolve all merge conflicts. |
@am1ter yes, I approve of the main idea of this PR and dropping 3.7 support. Please update the PR as you stated and we can go forward from there. Thanks for your efforts so far. |
Initially, my plan was to add features that I needed in my project. However, upon opening the source code, I realized that it was difficult to understand due to the lack of type annotations. Consequently, I decided to focus on adding type annotations to the codebase. While I am not very proficient in refactoring an existing library, I hope that you can provide me with advice on how to improve my commits or even take on the task yourself.
For this task, I used MyPy as a static type checker, which helped me ensure consistency in my annotations. Although I did not intend to refactor the codebase while adding type annotations, there were a few instances where I had to do so to resolve MyPy errors.
In addition to adding type annotations, I also created a new .py file containing all the type variables and aliases. I primarily used type aliases instead of custom types because refactoring to use new custom types would be more complex and dramatic. However, I believe it would be beneficial to consider this approach in the future.
I also made some minor changes to comments and support files.
I am confident that my refactoring did not impact any library functions. All tests passed on Python versions 3.7 through 3.11, as well as in PyPy3. Unfortunately, certain features cannot be implemented due to the need to support Python 3.7, which does not support Literals and isinstance() for Protocols.
P.S. MyPy and Flake8 checks also passed.