stubtest flags PEP 661 `sentinel` defaults, but not `object()` markers
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 75/100
Direzione di ricerca
Inizia con il controllo _verify_arg_default_value di stubtest, usando la riproduzione fornita con foo.py e foo.pyi ed eseguendo python -m mypy.stubtest foo. Verifica che un valore predefinito typing_extensions.sentinel venga trattato come un marcatore object() e che il comando non riporti errori, mentre i valori predefiniti ordinari incompatibili continuino a essere rilevati.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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_extensions4.16.0)
- Lingua principale
- Python
- Stelle
- 20.6k
- Fork
- 3.3k
- Merge medio
- 1g 18h
- PR unite (30g)
- 54
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di python/mypy
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
-
documentation
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
-
bug topic-configuration topic-error-reporting
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
-
bug topic-attrs
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
Issue simili
-
area/auth bug comp/agent P3 platform/discord type/security
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
NousResearch/hermes-agent#117848 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
bancolombia/sentinel#23 ·
-
test md ApertaCI
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
langchain-ai/deepagents#6450 ·
-
bug client
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100