-
Notifications
You must be signed in to change notification settings - Fork 766
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
Fail to handle property and init-only field with same name #3750
Comments
This behavior is correct. You are attempting to redefine the symbol You should use different names for the init variable and the property if you want this to work with a static type checker. |
Well I think it should not be too difficult to handle that since it's already detected that we have an init-only field, which could be completely ignored for each access against instance attributes. However if that's an issue that should rather be fixed in mypy than in pylance, I'll address it there |
This violates the Python type system, so there's nothing to "fix" in mypy. A symbol is not allowed to have two conflicting declarations. In your example, you've declared |
If you're not interested in static type checking, you can set |
@erictraut I am aware, but I don't see a real conflict here. What I see is a pseudo-conflict that will not be present at runtime. In my opinion the special characteristic of the init-only field is not sufficiently considered. Quoting the dataclass docs
|
Duplicates #python/mypy#12046 |
Environment data
Code Snippet
The text was updated successfully, but these errors were encountered: