Skip to content

Comments

Prohibit access via class for instance-only attributes#20855

Open
ilevkivskyi wants to merge 1 commit intopython:masterfrom
ilevkivskyi:prohibit-class-access-on-instance-var
Open

Prohibit access via class for instance-only attributes#20855
ilevkivskyi wants to merge 1 commit intopython:masterfrom
ilevkivskyi:prohibit-class-access-on-instance-var

Conversation

@ilevkivskyi
Copy link
Member

Fixes #240 (yes, you read that right, three digits)

I am taking a conservative approach and flag only cases that would definitely fail at runtime. Note we already have a more strict check for this for generics, but it is tricky to avoid double errors, so I think it is fine to have two errors sometimes.

I also update an outdated comment that confused me for a while.

@github-actions
Copy link
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

setuptools (https://github.com/pypa/setuptools)
+ setuptools/config/_apply_pyprojecttoml.py:328: error: Cannot access instance-only attribute "global_options" on class object  [misc]

@ilevkivskyi
Copy link
Member Author

setuptools error is correct. There is just too much monkey-patching for mypy to figure out where the base class with the attribute comes from.

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.

Disallow access to instance variable via class

1 participant