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
{{ message }}
Repository navigation
stubtest flags PEP 661 sentinel defaults, but not object() markers #22013
I was eager to try PEP661 support on master, but found what might be an oversight in stubtest. It flags sentinel usage against the stub's parameter type, while it does allow object-style marker objects. Since PEP661's sentinel is now the canonical way to write such a marker, I'd expect it to be allowed in such places:
error: foo.f is inconsistent, runtime parameter "x" has a default value of type typing_extensions.sentinel, which is incompatible with stub parameter type int
Stub: in file foo.pyi:1
def (x: int =)
Runtime: in file foo.py:5
def (x=_MISSING)
Found 1 error (checked 1 module)
I get the same on Python 3.15 beta.
As described above, adding the sentinel to the stub's type (x: int | _MISSING = ...) isn't an option.
The exemption seems to be in _verify_arg_default_value:
# Avoid false positives for marker objectsandtype(runtime_arg.default) isnotobject
It could be adjusted to include sentinel the same way.
Activity
JelleZijlstra commentedon Sep 21, 2026
I think we didn't consider stubtest when adding support (cc @edgarrmondragon). PR welcome!
edgarrmondragon commentedon Sep 21, 2026
I'm taking a look
UPDATE: #22017, but I'm curious if we're missing anything related to stubs for sentinels?
JelleZijlstra commentedon Sep 21, 2026
Your PR looks right, maybe we also need to change something in stubgen though?
edgarrmondragon commentedon Sep 21, 2026
Thanks for the hint, see #22019.
Fix stubtest false positive for sentinel default values (python#22017)
Handle arg=<sentinel value> in stubgen (#22019)