Self is not rejected when used as a PEP 695 type parameter bound
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 72/100
Línea de trabajo
Empieza con test-data/unit/check-selftype.test alrededor de la línea 1480 y reproduce el ejemplo de PEP 695 del issue. Sigue la validación existente de Self que se usa para otras ubicaciones no válidas y, después, añade cobertura para un límite o una restricción de un parámetro de tipo. Se considera terminado cuando mypy informa de un error para el ejemplo, mientras los tests existentes de Self siguen pasando.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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
- Lenguaje dominante
- Python
- Estrellas
- 20.6k
- Forks
- 3.3k
- Merge medio
- 1 d 18 h
- PR fusionados (30 d)
- 54
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de python/mypy
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
-
documentation
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
-
bug topic-configuration topic-error-reporting
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
Todos los issues de python/mypy
Issues similares
-
🐛 Bug 🔔 Pending processing
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
jumpserver/jumpserver#17584 ·
-
link-check link-check:sphinx-theme
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
qgis/QGIS-Documentation#11275 ·
-
bug priority:normal ready-for-dev
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
OpenHands/extensions#626 · 1 comentario ·
-
Change observation tooltip text Abierto
Dificultad 1/5 Menos de una hora Aptitud para principiantes 90/100
CSCfi/sd-search-api#39 ·