[issue33315] Allow queue.Queue to be used in type annotations

Ivan Levkivskyi report at bugs.python.org
Sun Apr 22 05:49:08 EDT 2018


Ivan Levkivskyi <levkivskyi at gmail.com> added the comment:

I think this issue appeared previously on typing tracker. The current recommendation is to escape problematic annotations with quotes:

q: 'Queue[int]'

I don't think it will be added to typing, because following this way typing will grow infinitely to include all generics in stdlib.

Another solution may be to add a simple `__class_getitem__` to `Queue` that will just return `cls` (so that we don't import `typing`). Although it will skip all the normal typing checks (so that `Queue[42]` will not raise at runtime), static type checkers like mypy will flag such errors. Guido, what do you think about such experiment?

----------
nosy: +gvanrossum, levkivskyi

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue33315>
_______________________________________


More information about the Python-bugs-list mailing list