You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There are differences between typing.Union and types.Union:
typing.Union is indexable, types.Union is not.
types.Union is a class, typing.Union is not.
types.Union corresponds to typing._UnionGenericAlias, not typing.Union. It is confusing that typing.Union and types.Union have the same name. Note also that most classes in the types module have the "Type" suffix: FunctionType, MethodType, ModuleType, etc. I think that it would be better to rename types.Union to types.UnionType.
This is a feature added to 3.10 so if we change it before the release there is no deprecation period needed. On the other hand if we don't get it to 3.10 is going to be much difficult to rename.
I agree that UnionType is marginally better so we should rename it. It doesn't seem worth doing if this doesn't make it in in time for 3.10, though. With the advent of PEP-604 typing.Union will hopefully become irrelevant.
Activity
serhiy-storchaka commentedon Jul 24, 2021
There are differences between typing.Union and types.Union:
types.Union corresponds to typing._UnionGenericAlias, not typing.Union. It is confusing that typing.Union and types.Union have the same name. Note also that most classes in the types module have the "Type" suffix: FunctionType, MethodType, ModuleType, etc. I think that it would be better to rename types.Union to types.UnionType.
AliyevH commentedon Jul 24, 2021
If nobody works on it i would like to fix it
AliyevH commentedon Jul 25, 2021
should have a deprecation period and if so, how long?
pablogsal commentedon Jul 25, 2021
This is a feature added to 3.10 so if we change it before the release there is no deprecation period needed. On the other hand if we don't get it to 3.10 is going to be much difficult to rename.
gvanrossum commentedon Jul 25, 2021
Agreed. I think we should do it, Serhiy’s reasoning makes sense.
We should just update the PEP and add a note that this was changed during the beta period.
JelleZijlstra commentedon Jul 26, 2021
I agree that UnionType is marginally better so we should rename it. It doesn't seem worth doing if this doesn't make it in in time for 3.10, though. With the advent of PEP-604 typing.Union will hopefully become irrelevant.
ambv commentedon Jul 26, 2021
New changeset 2b8ad9e by Hasan in branch 'main':
bpo-44732: Rename types.Union to types.UnionType (bpo-27342)
2b8ad9e
miss-islington commentedon Jul 26, 2021
New changeset 8a37e8c by Miss Islington (bot) in branch '3.10':
bpo-44732: Rename types.Union to types.UnionType (GH-27342)
8a37e8c