Repository navigation
invalid-sentinel - why does the argument have to be a literal? #4142
Description
Activity
I don't think it's a hard constraint, but we can't validate that the variable has the same name as the sentinel if we don't know the name statically
- addedneeds-discussionAn issue where it's not clear whether there is a bug or we are behaving as expected.An issue where it's not clear whether there is a bug or we are behaving as expected.
on Jul 21, 2026 ah, i must've missed this part of the PEP:
If the name passed to
sentinel()does not match the name the object is assigned to, type checkers should emit an error.ideally the type checker shouldn't have special-case an error when the argument isn't a
LiteralStringthough. that's typeshed's job. see these PRs:I don't think it's a hard constraint, but we can't validate that the variable has the same name as the sentinel if we don't know the name statically
looks like pyrefly currently doesn't do that:
foo = sentinel("bar") # no error
I don't think it's a hard constraint, but we can't validate that the variable has the same name as the sentinel if we don't know the name statically
Note that python/typing#2277 proposes to remove this text when adding this PEP to the spec and conformance suite.
I took a quick look, and pyrefly already falls back to the assigned name when
sentinelgets a non-literal argument, so I think we can relax this restriction. The discussion on the conformance test is ongoing, but in the current state, we don't need to check that the names match. We can add this error back if that changes.- added a commit that references this issue
on Jul 30, 2026 - added a commit that references this issue
on Aug 12, 2026
https://pyrefly.org/en/docs/error-kinds/#invalid-sentinel
this requirement doesn't seem to be mentioned in the docs or the PEP, but interestingly pyright also reports the same error. (ty doesn't)
i'm wondering if theres some documentation somewhere i'm missing, or if this just came from an early draft of the PEP that was later removed?