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

A dataclass of type enum.Enum does not contain the enum __members__ object #2317

Open
mbyrnepr2 opened this issue Oct 3, 2023 · 4 comments

Comments

@mbyrnepr2
Copy link
Member

mbyrnepr2 commented Oct 3, 2023

Steps to reproduce

See pylint-dev/pylint#9100 for context/original report.
A fix is made to Pylint to prevent the crash but work required in astroid to fix the root cause.

Current behavior

A false positive in Pylint for invalid-name:

from dataclasses import dataclass
from enum import Enum


@dataclass
class Something(str, Enum):
	asd: str = 1  # [invalid-name]

Expected behavior

No false positive

python -c "from astroid import __pkginfo__; print(__pkginfo__.version)" output

3.1.0-dev0

@jacobtylerwalls
Copy link
Member

Possibly related: #1730

@mbyrnepr2
Copy link
Member Author

mbyrnepr2 commented Oct 3, 2023

I don't think so @jacobtylerwalls. That issue is basically about excluding dunders from __members__ (it isn't necessarily about data classes) while this issue is specifically about __members__ not being available at all when dataclass decorator is used. (I have a rough solution for 1730 from the past week or so :D)

@DanielNoord
Copy link
Collaborator

Pitching #1598 again as it would be nice to broaden our support for instance variables 😄

Note that this is an issue in astroid, __members__ does exist:

from dataclasses import dataclass
from enum import Enum


@dataclass
class Something(str, Enum):
	asd: str = 1  # [invalid-name]

class OtherSomething(str, Enum):
    asd: str = 1  # [invalid-name]

print(Something.__members__)
print(OtherSomething.__members__)
python test.py
{'asd': <Something.asd: '1'>}
{'asd': <OtherSomething.asd: '1'>}

@mbyrnepr2
Copy link
Member Author

mbyrnepr2 commented Oct 3, 2023

Indeed @DanielNoord. Perhaps I was unclear in the comment. I meant that __members__ isn't present on the astroid representation of the class when it is decorated with dataclass. I agree that it exists on the Python class.

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

No branches or pull requests

3 participants