Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect signature for builtins.object.__dir__ #1871

Open
johanvdhaegen opened this issue Feb 16, 2025 · 0 comments
Open

Incorrect signature for builtins.object.__dir__ #1871

johanvdhaegen opened this issue Feb 16, 2025 · 0 comments

Comments

@johanvdhaegen
Copy link

Pytype requires an object's __dir__ method to return list[str], while Iterable[str] should be sufficient, according to the Python datamodel and typeshed's builtins.pyi.

The issue seems to be in pytype/stubs/builtins/builtins.pytd

For example, pytype incorrectly flags an error in the following test fragment:

from collections.abc import Iterable

class Foo:

  def __dir__(self) -> Iterable[str]:
    return super().__dir__()

Result:

test.py:5:3: error: in Foo: Overriding method signature mismatch [signature-mismatch]
  Base signature: 'def builtins.object.__dir__(self) -> list[str]'.
  Subclass signature: 'def Foo.__dir__(self) -> Iterable[str]'.
  Return type mismatch.

  def __dir__(self) -> Iterable[str]:
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    return super().__dir__()
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant