Inconsistent behaviour with / without a dummy type variable

Aperta
#20,442 2 commenti 0 reazioni 1 assegnatario Vedi su GitHub

@fury0928 ci sta già lavorando.

Dal 7/1/2026.

Valutazione

Questa issue non è ancora stata valutata.

Descrizione

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
Lingua principale
Python
Stelle
20.6k
Fork
3.3k
Merge medio
1g 18h
PR unite (30g)
54

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di python/mypy

Tutte le issue di python/mypy

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.