Skip to content

chore: use Final type annotation on every top-level constant #1010

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 1 commit into from
Feb 11, 2022

Conversation

mayeut
Copy link
Member

@mayeut mayeut commented Feb 5, 2022

per #996 (comment), this annotates top-level constants as such.

Copy link
Contributor

@joerick joerick left a comment

Choose a reason for hiding this comment

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

Why this type is called Final and not Const baffles me. But either way, looks good!

@henryiii
Copy link
Contributor

henryiii commented Feb 7, 2022

I think because it only refers to the reference assignment, not methods.

x: Final = [3]
x.append(4)

Is sadly completely valid. It protects against =, including +=, but does not understand "constness" of methods (which it can't, there's no const for methods in Python). It really is const only if the type is immutable.

@henryiii henryiii merged commit 27db835 into pypa:main Feb 11, 2022
@mayeut mayeut deleted the more-final-usage branch February 13, 2022 15:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants