You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: test-data/unit/check-expressions.test
+45Lines changed: 45 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -2380,6 +2380,51 @@ if 1 in ('x', 'y'): # E: Non-overlapping container check (element type: "int",
2380
2380
[builtins fixtures/tuple.pyi]
2381
2381
[typing fixtures/typing-full.pyi]
2382
2382
2383
+
[case testStrictEqualityWithAnySentinel]
2384
+
# flags: --strict-equality
2385
+
from __future__ import annotations
2386
+
from typing import Any, cast
2387
+
2388
+
class A: ...
2389
+
class B: ...
2390
+
2391
+
sentinel: Any = object()
2392
+
2393
+
def f1(a: A = sentinel, b: B = sentinel):
2394
+
if a is sentinel and b is sentinel:
2395
+
raise
2396
+
2397
+
2398
+
def f2(a: A | None = sentinel, b: B | None = sentinel):
2399
+
if a is sentinel and b is sentinel:
2400
+
raise
2401
+
2402
+
2403
+
sentinel_strict = object()
2404
+
2405
+
def f3(a: A = sentinel_strict, b: B = sentinel_strict): # E: Incompatible default for parameter "a" (default has type "object", parameter has type "A") \
2406
+
# E: Incompatible default for parameter "b" (default has type "object", parameter has type "B")
2407
+
if a is sentinel_strict and b is sentinel_strict: # E: Non-overlapping identity check (left operand type: "B", right operand type: "A")
2408
+
raise
2409
+
2410
+
2411
+
def f4(a: A | None = sentinel_strict, b: B | None = sentinel_strict): # E: Incompatible default for parameter "a" (default has type "object", parameter has type "A | None") \
2412
+
# E: Incompatible default for parameter "b" (default has type "object", parameter has type "B | None")
2413
+
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")
2414
+
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")
0 commit comments