Skip to content

Conversation

@Bibo-Joshi
Copy link

Type of Changes

Type
βœ“ πŸ› Bug fix

Description

Closes #6887

@Bibo-Joshi Bibo-Joshi changed the title Enum inherit slots Don't treat __slots__ as enum member Aug 2, 2022
@DanielNoord DanielNoord self-requested a review August 2, 2022 07:17
@coveralls
Copy link

Pull Request Test Coverage Report for Build 2780287184

  • 4 of 4 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.001%) to 95.253%

Totals Coverage Status
Change from base Build 2779654616: 0.001%
Covered Lines: 16834
Relevant Lines: 17673

πŸ’› - Coveralls

@github-actions
Copy link
Contributor

github-actions bot commented Aug 2, 2022

πŸ€– According to the primer, this change has no effect on the checked open source code. πŸ€–πŸŽ‰

This comment was generated for commit e9b8ad2

@mbyrnepr2
Copy link
Member

mbyrnepr2 commented Aug 2, 2022

Hi! I think the issue applies to any dunder name; not just __slots__. For example:

class E(Enum):
    __x__ = 'x'

class F(E):
    member = 3

pylint x.py:
x.py:7:0: E0244: Extending inherited Enum class "E" (invalid-enum-extension)

@Pierre-Sassoulas Pierre-Sassoulas added False Positive 🦟 A message is emitted but nothing is wrong with the code enum labels Aug 3, 2022
@Pierre-Sassoulas Pierre-Sassoulas added this to the 2.15.0 milestone Aug 3, 2022
@Bibo-Joshi
Copy link
Author

__x__ could be an actual enum member though, right? I guess the question is if non-standard dunder attributes should be treated as enum members or not. Personally I'd say yes.

Another thought that I head is that it might be better to have astroid handle this better directly such that we don't have to apply special casing here …

@Pierre-Sassoulas
Copy link
Member

+1 @Bibo-Joshi I did not follow everything here but if a fix can be done in astroid it's better to do it in astroid πŸ‘

@Bibo-Joshi
Copy link
Author

All right. I'll try to have a look into it or at least open an issue over at astroid :)

@mbyrnepr2
Copy link
Member

mbyrnepr2 commented Aug 3, 2022

__x__ could be an actual enum member though, right? I guess the question is if non-standard dunder attributes should be treated as enum members or not. Personally I'd say yes.

Another thought that I head is that it might be better to have astroid handle this better directly such that we don't have to apply special casing here …

It doesn't look like it. The dunder name does not appear in the members container:

(venv310) Marks-MacBook-Air-2:programming markbyrne$ cat y.py 
from enum import Enum


class E(Enum):
    __x__ = 'x'
    AAA = "aaa"

print(E.__members__)
print(type(E.AAA))
print(type(E.__x__))
(venv310) Marks-MacBook-Air-2:programming markbyrne$ python y.py 
{'AAA': <E.AAA: 'aaa'>}
<enum 'E'>
<class 'str'>

So I think the issue is Astroid is inserting them into members when it shouldn't be.

@Bibo-Joshi
Copy link
Author

All right. I'll try to have a look into it or at least open an issue over at astroid :)

Here it is: pylint-dev/astroid#1730. In any case, I guess this PR is superfluous. Closing.

@Pierre-Sassoulas
Copy link
Member

Thank you @Bibo-Joshi

@Pierre-Sassoulas Pierre-Sassoulas removed this from the 2.15.0 milestone Aug 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enum False Positive 🦟 A message is emitted but nothing is wrong with the code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

False positives invalid-enum-extension

4 participants