Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Change in inference of overloads involvingHashable andslice now thatslice is generic #18149

Closed
Labels
bugmypy got something wrong
@AlexWaygood

Description

@AlexWaygood

Bug Report

Consider the following Python snippet, saved asfoo.pyi:

fromtypingimportassert_type,overload,HashableclassFoo: ...classDataFrame:@overloaddef__getitem__(self,key:slice)->DataFrame: ...@overloaddef__getitem__(self,key:Hashable)->Foo: ...df=DataFrame()assert_type(df[1:],DataFrame)assert_type(df[:2],DataFrame)

Prior tothe recent change to makeslice generic in typeshed, mypy used to emit no errors on this snippet. However, mypy on themaster branch emits the following errors:

foo.pyi:7: error: Overloaded function signatures 1 and 2 overlap with incompatible return types  [overload-overlap]foo.pyi:13: error: Expression is of type "Any", not "DataFrame"  [assert-type]foo.pyi:14: error: Expression is of type "Any", not "DataFrame"  [assert-type]

The first error here seems reasonable to me, but it's unclear to me why mypy now infersAny as the result of thedf subscriptions. This snippet is minimized from the sole new mypy_primer error reported inpython/typeshed#11637 (comment).

To Reproduce

https://mypy-play.net/?mypy=master&python=3.12&gist=339ba7f72c9048770ce15d6dc75207a1

Your Environment

  • Mypy version used: mypy 1.14.0+dev.2ebc690279c7e20ed8bec006787030c5ba57c40e (compiled: no)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp