Inconsistent behaviour with / without a dummy type variable

Đang mở
#20,442 2 bình luận 0 reaction 1 người được giao Xem trên GitHub

@fury0928 đang làm issue này rồi.

Từ ngày 7/1/2026.

Đánh giá

Issue này chưa được đánh giá.

Mô tả

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
Ngôn ngữ chính
Python
Star
20.6k
Fork
3.3k
Merge trung bình
1 ngày 18 giờ
Pull request đã merge (30 ngày)
54

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của python/mypy

Tất cả issue của python/mypy

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.