-
Notifications
You must be signed in to change notification settings - Fork 48
Open
python/mypy
#20916Labels
bugpriority-0-highpython compatMypyc doesn't match CPython or documented semantics.Mypyc doesn't match CPython or documented semantics.
Description
Say a base class has defined __init_subclass__, and a class subclasses the base class. __init_subclass__ gets invoked automatically.
Inside the method, the subclass is missing any class variables declared on the subclass.
Other things such as methods and instance variable descriptors are not missing. The class variable works properly outside of __init_subclass__.
Since the subclass class variable is missing in __init_subclass__, accessing it either gives the class variable of the base class if defined, or an AttributeError if the base class has not defined the class variable.
from typing import ClassVar
class Base:
name: ClassVar[str] = "base"
def __init_subclass__(cls, **kwargs):
print(cls, cls.name)
class Sub(Base):
name: ClassVar[str] = "sub"$ mypyc main.py
...
$ python -c "import main"
<class 'module.Sub'> base
Version:
mypy 1.15.0 (compiled: yes)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugpriority-0-highpython compatMypyc doesn't match CPython or documented semantics.Mypyc doesn't match CPython or documented semantics.