Skip to content

Commit 5514980

Browse files
committed
is inferred
1 parent 8fbd288 commit 5514980

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

mypy/checkexpr.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3807,11 +3807,13 @@ def visit_comparison_expr(self, e: ComparisonExpr) -> Type:
38073807
and not (
38083808
isinstance(left, NameExpr)
38093809
and isinstance(left.node, Var)
3810+
and not left.node.is_inferred
38103811
and isinstance(get_proper_type(left.node.type), AnyType)
38113812
)
38123813
and not (
38133814
isinstance(right, NameExpr)
38143815
and isinstance(right.node, Var)
3816+
and not right.node.is_inferred
38153817
and isinstance(get_proper_type(right.node.type), AnyType)
38163818
)
38173819
):

test-data/unit/check-expressions.test

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2383,7 +2383,7 @@ if 1 in ('x', 'y'): # E: Non-overlapping container check (element type: "int",
23832383
[case testStrictEqualityWithAnySentinel]
23842384
# flags: --strict-equality
23852385
from __future__ import annotations
2386-
from typing import Any
2386+
from typing import Any, cast
23872387

23882388
class A: ...
23892389
class B: ...
@@ -2412,6 +2412,17 @@ def f4(a: A | None = sentinel_strict, b: B | None = sentinel_strict): # E: Inco
24122412
# E: Incompatible default for parameter "b" (default has type "object", parameter has type "B | None")
24132413
if a is sentinel_strict and b is sentinel_strict: # E: Non-overlapping identity check (left operand type: "B | None", right operand type: "A | None")
24142414
raise
2415+
2416+
2417+
sentinel_inferred = cast(Any, object())
2418+
2419+
def f5(a: A = sentinel_inferred, b: B = sentinel_inferred):
2420+
if a is sentinel_inferred and b is sentinel_inferred: # E: Non-overlapping identity check (left operand type: "B", right operand type: "A")
2421+
raise
2422+
2423+
def f6(a: A | None = sentinel_inferred, b: B | None = sentinel_inferred):
2424+
if a is sentinel_inferred and b is sentinel_inferred: # E: Non-overlapping identity check (left operand type: "B | None", right operand type: "A | None")
2425+
raise
24152426
[builtins fixtures/bool.pyi]
24162427

24172428
[case testOverlappingAnyTypeWithoutStrictOptional]

0 commit comments

Comments
 (0)