[New-bugs-announce] [issue32162] typing.Generic breaks __init_subclass__
Ilya Kulakov
report at bugs.python.org
Tue Nov 28 17:27:43 EST 2017
New submission from Ilya Kulakov <kulakov.ilya at gmail.com>:
When superclass inherits from Generic, attributes set for a subclass are incorrectly propagated to its superclass.
Without Generic attribute access raises an exception:
class X:
def __init_subclass__(cls, **kwargs):
super().__init_subclass__(**kwargs)
cls.attr = 42
class Y(X):
pass
Y.attr # 42
X.attr # AttributeError
With Generic it does not:
import typing
T = typing.TypeVar('T')
class X(typing.Generic[T]):
def __init_subclass__(cls, **kwargs):
super().__init_subclass__(**kwargs)
cls.attr = 42
class Y(X):
pass
Y.attr # 42
X.attr # 42
----------
messages: 307182
nosy: Ilya.Kulakov
priority: normal
severity: normal
status: open
title: typing.Generic breaks __init_subclass__
type: behavior
versions: Python 3.6
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue32162>
_______________________________________
More information about the New-bugs-announce
mailing list