should report ambiguous type variables in self types
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 35/100
Línea de trabajo
Reproduce the supplied Python example with mypy, focusing on the merge_method self type and its type-variable diagnostics. Trace the type-checking path that produces the shown Callable error; done means the example reports the ambiguity clearly and no longer suggests Tuple[int, int] as the expected callback type.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Example code:
from typing import TypeVar , Tuple, Generic, Iterable, Callable
T = TypeVar('T', covariant=True)
S = TypeVar('S')
class _Base(Generic[T]):
@classmethod
def split(self, left, right):
# type: (_Base[S], _Base[T]) -> _Base[Tuple[S, T]]
return Split(left, right)
@classmethod
def merge_classmethod(cls, base, f):
# type: (_Base[Iterable[T]], Callable[[Iterable[T]], T]) -> Merge[T]
return Merge(base, f)
# the type should use "S", not "T".
def merge_method(self, f):
# type: (_Base[Iterable[T]], Callable[[Iterable[T]], T]) -> Merge[T]
return Merge(self, f)
class Split(_Base[Tuple[S, T]]):
def __init__(self, left, right):
# type: (_Base[S], _Base[T]) -> None
pass
class Merge(_Base[T]):
def __init__(self, base, f):
# type: (_Base[Iterable[T]], Callable[[Iterable[T]], T]) -> None
pass
def _sum(xs):
# type: (Iterable[int]) -> int
return sum(xs)
x = _Base() # type: _Base[int]
# this typechecks
_Base.merge_classmethod(_Base.split(x, x), _sum)
# this doesn't:
# Argument 1 to "merge_method" of "_Base" has incompatible type "Callable[[Iterable[int]], int]"; expected "Callable[[Iterable[Tuple[int, int]]], Tuple[int, int]]"
_Base.split(x, x).merge_method(_sum)
the merge_method type annotation should be using a variable other than T—a more informative error message should go here.
- 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
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 90/100
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 86/100
zostera/django-bootstrap4#894 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
use-agent-os/agent-os#3276 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
zephyrproject-rtos/zephyr#119726 ·
-
area/auth bug comp/agent P3 platform/discord type/security
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
NousResearch/hermes-agent#117848 ·