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

Remove __slots__ from builtins.object #6800

Merged
merged 3 commits into from
Jan 9, 2022
Merged

Remove __slots__ from builtins.object #6800

merged 3 commits into from
Jan 9, 2022

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