TYP: Use Final and LiteralString for the constants in numpy.version#26975
Merged
seberg merged 1 commit intonumpy:mainfrom Jul 18, 2024
Merged
TYP: Use Final and LiteralString for the constants in numpy.version#26975seberg merged 1 commit intonumpy:mainfrom
Final and LiteralString for the constants in numpy.version#26975seberg merged 1 commit intonumpy:mainfrom
Conversation
Final constants in numpy.version and use LiteralStringFinal and LiteralString for the constants in numpy.version
seberg
reviewed
Jul 18, 2024
| 'release', | ||
| 'short_version', | ||
| 'version', | ||
| ) |
Member
There was a problem hiding this comment.
Curious, having __all__ is important for types in some way?
Member
Author
There was a problem hiding this comment.
In this case it should make a functional difference.
I mostly added it because "explicit is better than implicit", and because makes it easier for typecheckers to determine the public module members, which can help with performance.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
numpy.versionmembers are constants, and should be treated as such (overwriting them is possible, but a bad idea).The use of
typing.Finalhelps linters and type-checkers to recognize them as constants, even though their names aren't uppercase. These changes are backwards-compatible, unless the values are overwritten (but I can't imagine a usecase for this).For
python>=3.11thestrannotations have been replaced withtyping.LiteralString, which is fully backwards-compatible withstr. It will help typecheckers to identify the version strings as pre-defined constant values.In #26871 similar changes are made in the
numpynamespace.