Skip to content

Invalid instance.__slots__ type revealed #11891

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

Closed
sobolevn opened this issue Jan 3, 2022 · 2 comments
Closed

Invalid instance.__slots__ type revealed #11891

sobolevn opened this issue Jan 3, 2022 · 2 comments
Labels
bug mypy got something wrong

Comments

@sobolevn
Copy link
Member

sobolevn commented Jan 3, 2022

Here's a minimal repro:

class Bar(object):
    ...

reveal_type(Bar.__slots__)
reveal_type(Bar().__slots__)

Output:

out/ex.py:6: note: Revealed type is "typing.Iterable[builtins.str]"
out/ex.py:7: note: Revealed type is "typing.Iterable[builtins.str]"

What happens in runtime?

>>> class Bar(object):
...     ...
... 
>>> Bar.__slots__
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: type object 'Bar' has no attribute '__slots__'. Did you mean: '__class__'?
>>> Bar().__slots__
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'Bar' object has no attribute '__slots__'. Did you mean: '__class__'?

__slots__ are special.

Related #11885

@JelleZijlstra
Copy link
Member

Does the typeshed change fix this, or do you want to use this issue to track special-casing in mypy?

@ilevkivskyi
Copy link
Member

Mypy now reports an error on both lines.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

3 participants