[New-bugs-announce] [issue26391] Specialized sub-classes of Generic never call __init__
Kai Wohlfahrt
report at bugs.python.org
Fri Feb 19 06:52:22 EST 2016
New submission from Kai Wohlfahrt:
A specialized sub-class of a generic type never calls __init__ when it is instantiated. See below for an example:
from typing import Generic, TypeVar
T = TypeVar('T')
class Foo(Generic[T]):
def __init__(self, value: T):
self.value = value
Bar = Foo[str]
foo = Foo('foo')
bar = Bar('bar')
print(type(foo), end=' ')
print(foo.value)
print(type(bar), end=' ')
print(bar.value) # AttributeError
I would expect Foo[str], Foo[int], etc to be equivalent to Foo at run-time. If this is not the case it might deserve an explicit mention in the docs. At the moment, behaviour is confusing because an instance of Foo is returned that does not have any of its attributes set.
----------
messages: 260519
nosy: Kai Wohlfahrt
priority: normal
severity: normal
status: open
title: Specialized sub-classes of Generic never call __init__
type: behavior
versions: Python 3.5
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue26391>
_______________________________________
More information about the New-bugs-announce
mailing list