[spec] Can staticmethod calls infer type parameters for the containing class?
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Python
- Estrellas
- 1.8k
- Forks
- 302
- Merge medio
- 23 h
- PR fusionados (30 d)
- 8
Descripción
In this code:
from typing import TypeVar, Generic
T = TypeVar('T')
class Foo(Generic[T]):
@staticmethod
def create(arg: T) -> 'Foo[T]':
...
reveal_type(Foo.create(1234))
What should the type be? Should T be inferred based on the argument to the static method, resulting in Foo[int]? Or should it be Foo[Unknown] or similar?
mypy (python/mypy@fe15ee69b) picks Foo[int].
pyright used to choose Foo[int], but microsoft/pyright#7454 changed it to pick Foo[Unknown], on the grounds that this is required to comply with PEP 696's statement:
Type parameter defaults should be bound by attribute access (including call and subscript).
My example does not include any type parameter defaults, but I can see the logic of applying the same rule without one: you wouldn't want it to be a breaking change to add a default.
Still, why can't these kinds of static method calls be treated like constructor calls, where class type parameters can be inferred from arguments?
Guía de contribución
No hay ninguna guía de contribución indexada para este repositorio
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.
Línea de trabajo
Comienza revisando el ejemplo, las reglas de vinculación de PEP 696, el commit de mypy fe15ee69b y el issue de pyright referenciado. Determina el comportamiento acordado para las llamadas a staticmethod en clases genéricas y registra la decisión de especificación resultante, incluido si los comprobadores de tipos deben inferir Foo[int] o usar un tipo desconocido.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python
- Área
- devtools
- Tipo de issue
- Nueva funcionalidad
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Estado de actividad
- Estancado
- Claridad
- Necesita aclaración
- Aptitud para principiantes
- 25/100