stubtest flags PEP 661 `sentinel` defaults, but not `object()` markers

Open Beginner friendly
#22,013 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
75/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python
Domain
testing, tooling

Research direction

Start with stubtest's _verify_arg_default_value check, using the provided foo.py and foo.pyi reproduction and running python -m mypy.stubtest foo. Confirm that a typing_extensions.sentinel default is treated like an object() marker and that the command reports no errors while incompatible ordinary defaults remain detected.

Written by the indexing model from the issue text.

Description

bug

Bug Report

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:

To Reproduce

# foo.py
from typing_extensions import sentinel
_MISSING = sentinel("_MISSING")


def f(x=_MISSING):
    pass
# foo.pyi
def f(x: int = ...) -> None: ...
python -m mypy.stubtest foo

Expected Behavior

No errors, the same as with _MISSING = object():

Success: no issues found in 1 module

Actual Behavior

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 objects
and type(runtime_arg.default) is not object

It could be adjusted to include sentinel the same way.

My Environment

  • Mypy version used: master at 8d30064580c4273542f56ab2e9ed6a17caeea8ac (2.4.0+dev)
  • Mypy command-line flags: none
  • Mypy configuration options from mypy.ini (and other config files): none
  • Python version used: 3.14.7 (typing_extensions 4.16.0)
Dominant language
Python
Stars
20.6k
Forks
3.3k
Avg merge
1d 9h
Merged PRs (30d)
56

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from python/mypy

All issues in python/mypy

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.