python / typing_extensions

Backported and experimental type hints for Python
Other
446 stars 110 forks source link

Identity checks of `Literal` objects inconsistent between Python <3.10 and 3.10<= #361

Closed rsokl closed 8 months ago

rsokl commented 8 months ago
import typing
import typing_extensions as tp_ext

assert typing.Literal['a'] is typing.Literal['a']  # Passes for  Python 3.8<=
assert tp_ext.Literal['a'] is tp_ext.Literal['a']   # Fails for Python <3.10
JelleZijlstra commented 8 months ago

This isn't a guaranteed part of the interface, just as you may see differences in behavior for checks like 1 is 1 between Python versions.