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 serhiy.storchaka
Recipients gvanrossum, kj, serhiy.storchaka
Date 2022-03-11.08:21:12
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1646986872.43.0.932223345125.issue46981@roundup.psfhosted.org>
In-reply-to
Content
There are two empty typing.Tuple. They have the same repr but are not equal.

>>> from typing import *
>>> t1 = Tuple[()]
>>> t2 = t1.copy_with(())
>>> t1
typing.Tuple[()]
>>> t2
typing.Tuple[()]
>>> t1 == t2
False
>>> t1.__args__
((),)
>>> t2.__args__
()

The only differences is that one has empty __args__, while other has __args__ containing an empty tuple. There is a code purposed to make __args__ containing an empty tuple in this case. What is the purpose?

It is not pure theoretical question. This affects unpacked TypeVarTuple substitution. With natural implementation Tuple[Unpack[Ts]][()] is not equal to Tuple[()] and I still have not figured which and where code should be added to handle this special case. It would be easier if such special case did not exist.

Built-in tuple does not have a special case:

>>> tuple[()].__args__
()
History
Date User Action Args
2022-03-11 08:21:12serhiy.storchakasetrecipients: + serhiy.storchaka, gvanrossum, kj
2022-03-11 08:21:12serhiy.storchakasetmessageid: <1646986872.43.0.932223345125.issue46981@roundup.psfhosted.org>
2022-03-11 08:21:12serhiy.storchakalinkissue46981 messages
2022-03-11 08:21:12serhiy.storchakacreate