Skip to content

Commit 7bc5dac

Browse files
committed
clean up
1 parent 586d2a1 commit 7bc5dac

File tree

3 files changed

+17
-28
lines changed

3 files changed

+17
-28
lines changed

mypy/checker.py

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6549,7 +6549,10 @@ def comparison_type_narrowing_helper(self, node: ComparisonExpr) -> tuple[TypeMa
65496549
and not is_false_literal(expr)
65506550
and not is_true_literal(expr)
65516551
and not self.is_literal_enum(expr)
6552-
and not (isinstance(expr_type, CallableType) and expr_type.is_type_obj())
6552+
and not (
6553+
isinstance(p_expr := get_proper_type(expr_type), CallableType)
6554+
and p_expr.is_type_obj()
6555+
)
65536556
):
65546557
h = literal_hash(expr)
65556558
if h is not None:
@@ -6959,13 +6962,6 @@ def refine_identity_comparison_expression(
69596962
else:
69606963
type_targets.append((i, TypeRange(expr_type, is_upper_bound=False)))
69616964

6962-
if False:
6963-
print()
6964-
print("operands", operands)
6965-
print("operand_types", operand_types)
6966-
print("operator_specific_targets", operator_specific_targets)
6967-
print("type_targets", type_targets)
6968-
69696965
partial_type_maps = []
69706966

69716967
if operator_specific_targets:
@@ -6997,19 +6993,7 @@ def refine_identity_comparison_expression(
69976993
else_map = {}
69986994
partial_type_maps.append((if_map, else_map))
69996995

7000-
final_if_map, final_else_map = reduce_conditional_maps(
7001-
partial_type_maps, use_meet=len(operands) > 2
7002-
)
7003-
if False:
7004-
print(
7005-
"final_if_map",
7006-
{str(k): str(v) for k, v in final_if_map.items()} if final_if_map else None,
7007-
)
7008-
print(
7009-
"final_else_map",
7010-
{str(k): str(v) for k, v in final_else_map.items()} if final_else_map else None,
7011-
)
7012-
return final_if_map, final_else_map
6996+
return reduce_conditional_maps(partial_type_maps, use_meet=len(operands) > 2)
70136997

70146998
def refine_away_none_in_comparison(
70156999
self,
@@ -8534,9 +8518,10 @@ def and_conditional_maps(m1: TypeMap, m2: TypeMap, use_meet: bool = False) -> Ty
85348518
for n1 in m1:
85358519
for n2 in m2:
85368520
if literal_hash(n1) == literal_hash(n2):
8537-
result[n1] = meet_types(m1[n1], m2[n2])
8538-
if isinstance(result[n1], UninhabitedType):
8521+
meet_result = meet_types(m1[n1], m2[n2])
8522+
if isinstance(meet_result, UninhabitedType):
85398523
return None
8524+
result[n1] = meet_result
85408525
return result
85418526

85428527

@@ -8614,7 +8599,7 @@ def is_singleton_value(t: Type) -> bool:
86148599
"builtins.bytes",
86158600
"builtins.bytearray",
86168601
"builtins.memoryview",
8617-
"builtins.tuple",
8602+
# for Collection[Never]
86188603
"builtins.list",
86198604
"builtins.dict",
86208605
"builtins.set",
@@ -8627,7 +8612,10 @@ def has_custom_eq_checks(t: Type) -> bool:
86278612
or custom_special_method(t, "__ne__", check_all=False)
86288613
# TODO: make the hack more principled. explain what and why we're doing this though
86298614
# custom_special_method has special casing for builtins
8630-
or (isinstance(t, Instance) and t.type.fullname in BUILTINS_CUSTOM_EQ_CHECKS)
8615+
or (
8616+
isinstance(pt := get_proper_type(t), Instance)
8617+
and pt.type.fullname in BUILTINS_CUSTOM_EQ_CHECKS
8618+
)
86318619
)
86328620

86338621

mypy/test/testargs.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import argparse
1111
import sys
12+
from typing import Any, cast
1213

1314
from mypy.main import infer_python_executable, process_options
1415
from mypy.options import Options
@@ -63,7 +64,7 @@ def test_executable_inference(self) -> None:
6364

6465
# first test inferring executable from version
6566
options = Options()
66-
options.python_executable = None
67+
options.python_executable = cast(Any, None)
6768
options.python_version = sys.version_info[:2]
6869
infer_python_executable(options, special_opts)
6970
assert options.python_version == sys.version_info[:2]

mypy/test/testtypes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,12 +194,12 @@ def test_generic_function_type(self) -> None:
194194

195195
def test_type_alias_expand_once(self) -> None:
196196
A, target = self.fx.def_alias_1(self.fx.a)
197-
assert get_proper_type(A) == target
198197
assert get_proper_type(target) == target
198+
assert get_proper_type(A) == target
199199

200200
A, target = self.fx.def_alias_2(self.fx.a)
201-
assert get_proper_type(A) == target
202201
assert get_proper_type(target) == target
202+
assert get_proper_type(A) == target
203203

204204
def test_recursive_nested_in_non_recursive(self) -> None:
205205
A, _ = self.fx.def_alias_1(self.fx.a)

0 commit comments

Comments
 (0)