mypy
mypy copied to clipboard
Confusing error when subclassing `var.__class__`
Consider this example:
x: int = 1
class X(x.__class__):
# Name "x.__class__" is not defined
# Class cannot subclass "__class__" (has type "Any")
pass
Name "x.__class__" is not defined
is confusing. Why x.__class__
is considered a name? I suggest removing this error in this case.
My Environment
-
mypy 0.961 (compiled: no)
- no command-line flags, no config file
-
CPython 3.10.4
- Windows 10
is this related to this issue: https://github.com/python/mypy/issues/4177 ?
~Yes, this is a duplicate of https://github.com/python/mypy/issues/4177.~
Edit: As Alex points out below, this isn't a duplicate.
Yes, this is a duplicate of #4177.
No, it's not a duplicate, I don't think. This issue is about mypy not recognising the object.__class__
attribute. #4177 is about mypy not recognising the magic __class__
variable that is implicitly inserted into the scope of all methods in Python.