Self is not rejected when used as a PEP 695 type parameter bound
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 72/100
Direzione di ricerca
Inizia da test-data/unit/check-selftype.test intorno alla riga 1480 e riproduci l’esempio PEP 695 dell’issue. Segui la validazione esistente di Self usata per le altre posizioni non valide, quindi aggiungi la copertura per un bound o un vincolo di un parametro di tipo. Il lavoro è completo quando mypy segnala un errore per l’esempio, mentre i test Self esistenti continuano a passare.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Bug Report
Self is only valid in the specific locations listed in PEP 673 and Mypy already rejects several invalid locations.
See: https://github.com/python/mypy/blob/ae39cdb2fba8908eeff6ec8d6b88879c62495fcc/test-data/unit/check-selftype.test#L1480
It seems one location wasn't covered: using Self as the bound (or constraint) of a PEP 695 type parameter.
To Reproduce:
from typing import Self
class Foo:
def fails[T: Self](self: T) -> None: pass
Expected Behavior
Mypy should reject Self here with an error.
From a quick look at other type checkers: pyright and ty treat it as an invalid/generic TypeVar bound (TypeVar upper bound cannot be generic), while zuban rejects it with the same message mypy already uses elsewhere,
Self type is only allowed in annotations within class definition.
Actual Behavior
No error is reported.
Your Environment
Mypy version: https://github.com/python/mypy/commit/ae39cdb2fba8908eeff6ec8d6b88879c62495fcc
Python version: 3.12
TLDR; originally spotted while working on #21928 See: https://github.com/python/mypy/pull/21928#issuecomment-5557910054
- Lingua principale
- Python
- Stelle
- 20.6k
- Fork
- 3.3k
- Merge medio
- 1g 12h
- PR unite (30g)
- 58
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
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
anthropics/skills#1811 · 1 commento ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
speaches-ai/speaches#678 ·
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
datalayer/mcp-compose#42 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
conda-forge/spacy-feedstock#177 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
UKGovernmentBEIS/inspect_evals#2523 ·