Title: typing.Union unifies types too broadly
Type: behavior Stage: test needed
Components: Extension Modules Versions: Python 3.6, Python 3.5
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: alex.gronholm, ezio.melotti, gvanrossum, levkivskyi, lukasz.langa
Priority: normal Keywords:

Created on 2016-01-10 12:57 by alex.gronholm, last changed 2016-09-27 22:25 by gvanrossum. This issue is now closed.

Messages (3)
msg257910 - (view) Author: Alex Grönholm (alex.gronholm) * Date: 2016-01-10 12:57
>>> from typing import Union, Iterable
>>> Union[str, Iterable[int]]

The union loses the "str" parameter because issubclass(str, returns True and the check completely disregards generics.

Guido mentioned that issubclass() support for generic types should be going away. In the mean time, maybe the subclass check in typing.GenericMeta should be modified not to do it with types from Typing, but how can we accurately identify them?
msg257925 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2016-01-10 18:25
Oh, this is yet another reason to finally rip out the issubclass() support...  We're tracking that at

In the meantime, just don't do this!
msg277559 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2016-09-27 22:25
Fixed by 09cc43df4509.
Date User Action Args
2016-09-27 22:25:19gvanrossumsetstatus: open -> closed
resolution: fixed
messages: + msg277559
2016-06-30 22:07:35levkivskyisetnosy: + levkivskyi
2016-01-10 18:25:26gvanrossumsetmessages: + msg257925
2016-01-10 13:41:14ezio.melottisetnosy: + ezio.melotti

stage: test needed
2016-01-10 12:57:34alex.gronholmcreate