Skip to content

Conversation

@sobolevn
Copy link
Member

@sobolevn sobolevn commented Jan 3, 2022

I invite everyone to discuss this problem 🙂

Technically, object does not have __slots__ defined:

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

And its subclasses do not have __slots__:

>>> 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__'?

We need to explicitly specify that some type has __slots__.

Maybe it is better to special-case __slots__ in type-checker? It is not hard to check that class-level field named __slots__ is str | Iterable[str] 🤔

Related python/mypy#11891 and python/mypy#11885

@github-actions

This comment has been minimized.

2 similar comments
@github-actions

This comment has been minimized.

@github-actions
Copy link
Contributor

github-actions bot commented Jan 3, 2022

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@srittau
Copy link
Collaborator

srittau commented Jan 3, 2022

Considering that all checks pass and primer has no complaints, I'm +1 on this change.

@Akuli
Copy link
Collaborator

Akuli commented Jan 3, 2022

I don't have a strong opinion on this, as I don't think there's much practical impact. Even __slots__ = ("foo", "bar") is quite rare.

@sobolevn
Copy link
Member Author

sobolevn commented Jan 3, 2022

I don't have a strong opinion on this, as I don't think there's much practical impact.

See python/mypy#11885

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

Successfully merging this pull request may close these issues.

4 participants