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

Support for Final-as-default, like Rust #16313

Open
willhansen opened this issue Oct 22, 2023 · 2 comments
Open

Support for Final-as-default, like Rust #16313

willhansen opened this issue Oct 22, 2023 · 2 comments

Comments

@willhansen
Copy link

Feature

If I want to follow "best practices", I've got to put a Final[ ] wrapper around most type hints I use. Could there be a mypy flag to assume every type hint is final unless it's got a Mut[ ] wrapper?

Would probably require a search-replace script to convert a project between the modes, but that doesn't sound too bad.

Pitch

Variables being constant when you won't need to change them is generally regarded as a good idea, right? This would make it easier, like Rust does.

I don't know about any of the mypy internals, but this doesn't strike me as too big a change?

Interface change would be a new --final-as-default flag.

@sobolevn
Copy link
Member

I love this idea :)

I think that it needs to be clarified, that the flag should be something like --implicit-final-vars, because final might also mean classes, methods, etc.

@takeda
Copy link

takeda commented May 25, 2024

Yes! I'm making myself to use Final in my code frequently and most of the time the variables aren't really mutated, so having a mode where Final would be implicit would be really helpful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants