In 3.10 the union type (the type of the result of the | operator for types) was added (https://www.python.org/dev/peps/pep-0604/). It is exposed as types.Union. 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 private class typing._UnionGenericAlias, not typing.Union. It is confusing that typing.Union and types.Union have the same name but are so different. 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. The name of types.Union is the part of already accepted PEP 604, so we need to hear opinions of authors, sponsor and BDFL-delegate of the PEP. I did not participate in the discussion about PEP 604 so I do not know if there are arguments in favor of types.Union over types.UnionType.
On Sun, 25 Jul 2021, 9:26 pm Serhiy Storchaka, <storchaka@gmail.com> wrote:
In 3.10 the union type (the type of the result of the | operator for types) was added (https://www.python.org/dev/peps/pep-0604/). It is exposed as types.Union. 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 private class typing._UnionGenericAlias, not typing.Union. It is confusing that typing.Union and types.Union have the same name but are so different. 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.
If we wanted to be completely explicit, the most exact name would be "TypeUnionType": it is the type of object you get specifically when unioning types, not when unioning arbitrary objects. Cheers, Nick.
I don't think that's how we name things. (Though it's a great tongue twister. :-) On Mon, Jul 26, 2021 at 1:33 AM Nick Coghlan <ncoghlan@gmail.com> wrote:
On Sun, 25 Jul 2021, 9:26 pm Serhiy Storchaka, <storchaka@gmail.com> wrote:
In 3.10 the union type (the type of the result of the | operator for types) was added (https://www.python.org/dev/peps/pep-0604/). It is exposed as types.Union. 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 private class typing._UnionGenericAlias, not typing.Union. It is confusing that typing.Union and types.Union have the same name but are so different. 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.
If we wanted to be completely explicit, the most exact name would be "TypeUnionType": it is the type of object you get specifically when unioning types, not when unioning arbitrary objects.
Cheers, Nick.
_______________________________________________ Python-Dev mailing list -- python-dev@python.org To unsubscribe send an email to python-dev-leave@python.org https://mail.python.org/mailman3/lists/python-dev.python.org/ Message archived at https://mail.python.org/archives/list/python-dev@python.org/message/3O6STJNH... Code of Conduct: http://python.org/psf/codeofconduct/
-- --Guido van Rossum (python.org/~guido) *Pronouns: he/him **(why is my pronoun here?)* <http://feministing.com/2015/02/03/how-using-they-as-a-singular-pronoun-can-change-the-world/>
Great point, Serhiy. I agree it would be very confusing to have types.Union and typing.Union. types.UnionType, types.TypeUnionType, types.UnionTypeType all are much better IMHO. Cheers, Luciano On Sun, Jul 25, 2021 at 8:25 AM Serhiy Storchaka <storchaka@gmail.com> wrote:
In 3.10 the union type (the type of the result of the | operator for types) was added (https://www.python.org/dev/peps/pep-0604/). It is exposed as types.Union. 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 private class typing._UnionGenericAlias, not typing.Union. It is confusing that typing.Union and types.Union have the same name but are so different. 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.
The name of types.Union is the part of already accepted PEP 604, so we need to hear opinions of authors, sponsor and BDFL-delegate of the PEP.
I did not participate in the discussion about PEP 604 so I do not know if there are arguments in favor of types.Union over types.UnionType.
_______________________________________________ Python-Dev mailing list -- python-dev@python.org To unsubscribe send an email to python-dev-leave@python.org https://mail.python.org/mailman3/lists/python-dev.python.org/ Message archived at https://mail.python.org/archives/list/python-dev@python.org/message/RHRF7Q25... Code of Conduct: http://python.org/psf/codeofconduct/
-- Luciano Ramalho | Author of Fluent Python (O'Reilly, 2015) | http://shop.oreilly.com/product/0636920032519.do | Technical Principal at ThoughtWorks | Twitter: @ramalhoorg
participants (4)
-
Guido van Rossum
-
Luciano Ramalho
-
Nick Coghlan
-
Serhiy Storchaka