Skip to content

Commit e377115

Browse files
committed
Revert attempt to fix Mapping.get
1 parent 43c097c commit e377115

File tree

3 files changed

+6
-32
lines changed

3 files changed

+6
-32
lines changed

mypy/checkexpr.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,6 @@
139139
get_all_type_vars,
140140
get_type_vars,
141141
is_literal_type_like,
142-
is_literal_type_like_or_singleton,
143142
make_simplified_union,
144143
simple_literal_type,
145144
true_only,
@@ -2043,7 +2042,7 @@ def infer_function_type_arguments_using_context(
20432042
# expects_literal(identity(3)) # Should type-check
20442043
# TODO: we may want to add similar exception if all arguments are lambdas, since
20452044
# in this case external context is almost everything we have.
2046-
if not is_generic_instance(ctx) and not is_literal_type_like_or_singleton(ctx):
2045+
if not is_generic_instance(ctx) and not is_literal_type_like(ctx):
20472046
return callable.copy_modified()
20482047
args = infer_type_arguments(
20492048
callable.variables, ret_type, erased_ctx, skip_unsatisfied=True

mypy/typeops.py

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,27 +1005,6 @@ def is_literal_type_like(t: Type | None) -> bool:
10051005
return False
10061006

10071007

1008-
def is_literal_type_like_or_singleton(t: Type | None) -> bool:
1009-
"""Returns 'true' if the given type context is potentially either a LiteralType,
1010-
a Union of LiteralType, a singleton (or a union thereof), or something similar.
1011-
"""
1012-
t = get_proper_type(t)
1013-
if t is None:
1014-
return False
1015-
elif isinstance(t, LiteralType):
1016-
return True
1017-
elif t.is_singleton_type():
1018-
return True
1019-
elif isinstance(t, UnionType):
1020-
return any(is_literal_type_like_or_singleton(item) for item in t.items)
1021-
elif isinstance(t, TypeVarType):
1022-
return is_literal_type_like_or_singleton(t.upper_bound) or any(
1023-
is_literal_type_like_or_singleton(item) for item in t.values
1024-
)
1025-
else:
1026-
return False
1027-
1028-
10291008
def is_singleton_type(typ: Type) -> bool:
10301009
"""Returns 'true' if this type is a "singleton type" -- if there exists
10311010
exactly only one runtime value associated with this type.

test-data/unit/check-inference-context.test

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1511,18 +1511,14 @@ def check(paths: Iterable[str], key: Callable[[str], int]) -> Union[str, None]:
15111511
return mymin(paths, key=key, default=None)
15121512
[builtins fixtures/tuple.pyi]
15131513

1514-
[case testInferenceContextLiteralInstance]
1515-
from collections.abc import Callable, Iterable, Mapping
1516-
from enum import Enum
1517-
from typing import Final, Generic, Literal, TypeVar, Union
1518-
1519-
class Opt(Enum):
1520-
MISSING = "MISSING"
1514+
[case testInferenceContextMappingGet-xfail]
1515+
from collections.abc import Mapping
1516+
from typing import TypeVar, Union
15211517

1522-
MISSING: Final[Literal[Opt.MISSING]] = Opt.MISSING
15231518
_T1 = TypeVar("_T1")
15241519

15251520
def check(mapping: Mapping[str, _T1]) -> None:
1526-
res: Union[_T1, Opt] = mapping.get("", MISSING)
1521+
fail1 = mapping.get("", "")
1522+
fail2: Union[_T1, str] = mapping.get("", "")
15271523
[builtins fixtures/tuple.pyi]
15281524
[typing fixtures/typing-full.pyi]

0 commit comments

Comments
 (0)