[New-bugs-announce] [issue46981] Empty typing.Tuple
Serhiy Storchaka
report at bugs.python.org
Fri Mar 11 03:21:12 EST 2022
New submission from Serhiy Storchaka <storchaka+cpython at gmail.com>:
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__
()
----------
components: Library (Lib)
messages: 414892
nosy: gvanrossum, kj, serhiy.storchaka
priority: normal
severity: normal
status: open
title: Empty typing.Tuple
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue46981>
_______________________________________
More information about the New-bugs-announce
mailing list