Inconsistent behaviour with / without a dummy type variable

Abierto
#20,442 2 comentarios 0 reacciones 1 asignado Ver en GitHub

@fury0928 ya está trabajando en esto.

Desde el 7/1/2026.

Evaluación

Este issue todavía no se ha evaluado.

Descripción

bug

Bug Report

mypy behaves differently with and without an unfunctional type variable.

To Reproduce

from typing_extensions import TypeVar, Self, reveal_type
from typing import Any, Generic, overload
from collections.abc import Callable, Hashable, Iterable

IndexT0 = TypeVar("IndexT0")
T = TypeVar("T")


class Series:
    pass


class _LocIndexerFrame(Generic[T]):
    @overload
    def __getitem__(
        self, idx: "tuple[Callable[[DataFrame], int], str]"
    ) -> int: ...
    @overload
    def __getitem__(
        self, idx: "tuple[Callable[[DataFrame], list[Hashable]], str]"
    ) -> Series: ...
    @overload
    def __getitem__(
        self, idx: "tuple[Callable[[DataFrame], Any], Iterable[Hashable]]"
    ) -> T: ...
    def __getitem__(self, idx: object) -> object:
        return  # type: ignore[return-value]


class DataFrame(Generic[IndexT0]):
    @property
    def loc(self) -> _LocIndexerFrame[Self]:
        return _LocIndexerFrame()


def select2(df: DataFrame) -> list[Hashable]:
    return []


reveal_type(DataFrame().loc[select2, "x"])  # pyright gives Series, mypy gives Any


def select3(_: DataFrame) -> int:
    return 1


reveal_type(DataFrame().loc[select3, "x"])  # pyright gives int, mypy gives Any

Expected Behavior

Same results from the two playground links, since the type variable is not functional

Actual Behavior

Different results.

Your Environment

  • Mypy version used: 1.19.1
  • Mypy command-line flags: None
  • Mypy configuration options from mypy.ini (and other config files): None
  • Python version used: 3.12, 3.14
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

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de python/mypy

Todos los issues de python/mypy

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.