Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions pyrefly/lib/solver/subset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3029,6 +3029,14 @@ impl<'solver, 'subset, Ans: LookupAnswer> Subset<'solver, 'subset, Ans> {
.heap
.mk_class_type(self.type_order.stdlib().none_type().clone()),
),
// A sentinel value is an instance of the runtime `sentinel` class.
(Type::Sentinel(_), _) => self.is_subset_eq(
&self
.solver
.heap
.mk_class_type(self.type_order.stdlib().sentinel().clone()),
want,
),
(Type::Forall(forall), _) => {
let got = self.instantiate_fresh_forall((**forall).clone(), want);
self.is_subset_forall(got, want)
Expand Down
34 changes: 34 additions & 0 deletions pyrefly/lib/test/sentinel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,40 @@ B: A = Sentinel("B") # E: `sentinel` is not assignable to `A`
"#,
);

testcase!(
test_sentinel_is_instance_of_runtime_class,
r#"
from typing_extensions import Sentinel

MISSING = Sentinel("MISSING")
OTHER = Sentinel("OTHER")

value: Sentinel = MISSING

def f(value: int | Sentinel = MISSING) -> Sentinel:
return OTHER

def g(value: Sentinel) -> None:
specific: MISSING = value # E: `sentinel` is not assignable to `MISSING`

different: MISSING = OTHER # E: `OTHER` is not assignable to `MISSING`
not_class: type[Sentinel] = MISSING # E: `MISSING` is not assignable to `type[sentinel]`
"#,
);

testcase!(
test_builtin_sentinel_is_instance_of_runtime_class_3_15,
TestEnv::new().with_version(PythonVersion::new(3, 15, 0)),
r#"
from typing_extensions import Sentinel

BUILTIN = sentinel("BUILTIN")
UPPER = Sentinel("UPPER")

def f(value: int | sentinel = BUILTIN, other: sentinel = UPPER) -> None: ...
"#,
);

testcase!(
test_sentinel_typehint_any,
r#"
Expand Down
Loading