This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author gvanrossum
Recipients Kai Wohlfahrt, gvanrossum
Date 2016-03-23.20:41:57
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1458765718.2.0.271478140613.issue26391@psf.upfronthosting.co.za>
In-reply-to
Content
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!
History
Date User Action Args
2016-03-23 20:41:58gvanrossumsetrecipients: + gvanrossum, Kai Wohlfahrt
2016-03-23 20:41:58gvanrossumsetmessageid: <1458765718.2.0.271478140613.issue26391@psf.upfronthosting.co.za>
2016-03-23 20:41:58gvanrossumlinkissue26391 messages
2016-03-23 20:41:57gvanrossumcreate