[issue26391] Specialized sub-classes of Generic never call __init__

2016-03-23 Thread Guido van Rossum

Guido van Rossum added the comment:

You've hit a type where PEP 484 and mypy disagree.

The PEP shows a few examples of this:
https://www.python.org/dev/peps/pep-0484/#instantiating-generic-classes-and-type-erasure

However when I feed the examples from the PEP to mypy I get an error on each of 
the last two lines:

-
from typing import TypeVar, Generic
T = TypeVar('T')
class Node(Generic[T]):
pass
x = Node[T]()
y = Node[int]()
-
b.py:5: error: Invalid type "b.T"
b.py:5: error: Generic type not valid as an expression any more (use '# type:' 
comment instead)
b.py:6: error: Generic type not valid as an expression any more (use '# type:' 
comment instead)

I suspect that mypy is right and the PEP didn't catch up to the change of mind 
in the flurry of activity right before acceptance.

Since it's provisional I'd like to change the PEP to disallow this.

At the same time at runtime I think it should either fail loudly or work, not 
silently return an uninitialized instance, so typing.py also needs to be fixed.

Thanks for the report!

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26391] Specialized sub-classes of Generic never call __init__

2016-03-23 Thread SilentGhost

Changes by SilentGhost :


--
nosy: +gvanrossum

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26391] Specialized sub-classes of Generic never call __init__

2016-02-19 Thread Kai Wohlfahrt

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 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com