Skip to content

Commit 41f9383

Browse files
Do not treat sentinel reassignment as an alias
e.g. ```python MISSING = sentinel("MISSING") ALIAS = MISSING ``` N.B. `ALIAS` is no loses the singleton identity, so it's no longer accepted wherever `MISSING` is expected. Signed-off-by: Edgar Ramírez Mondragón <[email protected]>
1 parent f6e5a5c commit 41f9383

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

‎mypy/semanal.py‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3609,8 +3609,6 @@ def is_type_ref(self, rv: Expression, bare: bool = False) -> bool:
36093609
# Assignment color = Color['RED'] defines a variable, not an alias.
36103610
return not rv.node.is_enum
36113611
if isinstance(rv.node, Var):
3612-
if rv.node.is_sentinel:
3613-
return True
36143612
return rv.node.fullname in NEVER_NAMES
36153613

36163614
if isinstance(rv, NameExpr):

‎test-data/unit/check-sentinels.test‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,3 +153,18 @@ def func(x: int | BUILTIN | TYPEXT) -> None:
153153
assert_type(x, int)
154154

155155
[builtins fixtures/sentinel.pyi]
156+
157+
[case testSentinelReassignmentIsNotTypeAlias]
158+
from typing_extensions import sentinel, assert_type
159+
160+
MISSING = sentinel("MISSING")
161+
ALIAS = MISSING
162+
163+
assert_type(ALIAS, sentinel)
164+
165+
def func(x: int | MISSING = MISSING) -> None:
166+
pass
167+
168+
func(MISSING)
169+
func(ALIAS) # E: Argument 1 to "func" has incompatible type "Sentinel"; expected "int | MISSING"
170+
[builtins fixtures/tuple.pyi]

0 commit comments

Comments
 (0)