mirror of
https://github.com/python/cpython.git
synced 2025-08-03 08:34:29 +00:00
bpo-45679: Fix caching of multi-value typing.Literal (GH-29334)
Literal[True, 2] is no longer equal to Literal[1, 2].
(cherry picked from commit 634984d7db
)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
parent
da222b7cc8
commit
3997f3ce8a
3 changed files with 11 additions and 6 deletions
|
@ -403,9 +403,10 @@ class _SpecialForm(_Final, _root=True):
|
|||
|
||||
|
||||
class _LiteralSpecialForm(_SpecialForm, _root=True):
|
||||
@_tp_cache(typed=True)
|
||||
def __getitem__(self, parameters):
|
||||
return self._getitem(self, parameters)
|
||||
if not isinstance(parameters, tuple):
|
||||
parameters = (parameters,)
|
||||
return self._getitem(self, *parameters)
|
||||
|
||||
|
||||
@_SpecialForm
|
||||
|
@ -528,7 +529,8 @@ def Optional(self, parameters):
|
|||
return Union[arg, type(None)]
|
||||
|
||||
@_LiteralSpecialForm
|
||||
def Literal(self, parameters):
|
||||
@_tp_cache(typed=True)
|
||||
def Literal(self, *parameters):
|
||||
"""Special typing form to define literal types (a.k.a. value types).
|
||||
|
||||
This form can be used to indicate to type checkers that the corresponding
|
||||
|
@ -551,9 +553,6 @@ def Literal(self, parameters):
|
|||
"""
|
||||
# There is no '_type_check' call because arguments to Literal[...] are
|
||||
# values, not types.
|
||||
if not isinstance(parameters, tuple):
|
||||
parameters = (parameters,)
|
||||
|
||||
parameters = _flatten_literal_params(parameters)
|
||||
|
||||
try:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue