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
False error about redeclaration of Final private(double-underscore) variables #725
Comments
|
The behavior is correct as per PEP 591. As confirmation, the same error is emitted by other type checkers like mypy. |
I think one could make the argument that PEP 591 should make an exception for class members with double-underscore names since they are obfuscated and therefore cannot conflict with same-named members in parent classes. @gvanrossum, I'm interest in any advice you can offer here. |
Your are right that mypy has the same behavior. But I'm quite confused that |
I know there's sort of a question as to whether or not |
The |
I've updated the logic in pyright to exempt private (double underscored) symbols from this check. @gvanrossum, you can decide whether to update PEP 591 to reflect this exemption. Also, it appears that mypy may need to also apply this fix. I've also fixed the logic for single-underscore methods. |
I don't see why PEP 591 should be updated -- the two |
That logic makes sense, yet both pyright and mypy maintainers missed this point (or came to different conclusions) because PEP 591 didn't say anything on the topic. |
Okay, that's fair.
|
This issue has been fixed in version 2021.1.2, which we've just released. You can find the changelog here: https://github.com/microsoft/pylance-release/blob/main/CHANGELOG.md#202112-20-january-2021 |
Environment data
Actual behavior
The code above is largely simplified and
__init__
methods are there only to suppress "final but not assigned" errors and "unused" warnings.Expected behavior
No error.
Reason
A class member named with a prefix of double-underscore and without a suffix of double-underscore is meant to be purely private. There should be no collisions between such members even if they share a same name.
The text was updated successfully, but these errors were encountered: