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

Should SomeStrEnum(str, Enum) require SLOT000? #5748

Closed
charliermarsh opened this issue Jul 13, 2023 Discussed in #5747 · 4 comments · Fixed by #5749
Closed

Should SomeStrEnum(str, Enum) require SLOT000? #5748

charliermarsh opened this issue Jul 13, 2023 Discussed in #5747 · 4 comments · Fixed by #5749
Assignees
Labels
accepted Ready for implementation bug Something isn't working

Comments

@charliermarsh
Copy link
Member

Discussed in #5747

Originally posted by jamesbraza July 13, 2023
Please see the below file with Python 3.10.10:

from enum import Enum

class SomeStrEnum(str, Enum):
    KEY = "value"

Running ruff==0.0.278 on this:

> ruff --isolated --select="SLOT" a.py
a.py:3:7: SLOT000 Subclasses of `str` should define `__slots__`
Found 1 error.

Running flake8-slots==0.1.5 with flake8==4.0.1 on this, there's no error:

> flake8 a.py

Fwiw, Python 3.11's built-in enum.StrEnum doesn't seem to define __slots__.

I am not sure if there should or should not be SLOT000 for this. Looks like @qdegraaf added SLOT rule in ruff==0.0.273, so notifying him.

I am thinking either:

  • This is a false positive of SLOT000
  • Or should the built-in StrEnum define __slots__?
@charliermarsh
Copy link
Member Author

Looks like flake8-slots omits enums: https://github.com/python-formate/flake8-slots/blob/0b1ecb9076c6194f29265b7bfb904d63073bce08/flake8_slots/__init__.py#L102.

@charliermarsh charliermarsh added bug Something isn't working accepted Ready for implementation labels Jul 13, 2023
@charliermarsh charliermarsh self-assigned this Jul 13, 2023
charliermarsh added a commit that referenced this issue Jul 13, 2023
## Summary

Matches the behavior of the upstream plugin.

Closes #5748.
evanrittenhouse pushed a commit to evanrittenhouse/ruff that referenced this issue Jul 19, 2023
)

## Summary

Matches the behavior of the upstream plugin.

Closes astral-sh#5748.
konstin pushed a commit that referenced this issue Jul 19, 2023
## Summary

Matches the behavior of the upstream plugin.

Closes #5748.
@sujuka99
Copy link

Is this expected?

class SuperEnum(Enum):
	...

class CustomStrEnum(str, SuperEnum):  # Results in "SLOT000 Subclasses of `str` should define `__slots__`"
	...

@charliermarsh
Copy link
Member Author

Yeah, we don't trace across base classes right now. You'd need to add Enum as a parent class to have it detected properly.

@sujuka99
Copy link

Yeah, we don't trace across base classes right now. You'd need to add Enum as a parent class to have it detected properly.

Thanks for the quick answer :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted Ready for implementation bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants