-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Check that a name exists inside enum.Enum
class' __members__
.
#8905
Check that a name exists inside enum.Enum
class' __members__
.
#8905
Conversation
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #8905 +/- ##
=======================================
Coverage 95.75% 95.75%
=======================================
Files 173 173
Lines 18652 18655 +3
=======================================
+ Hits 17860 17863 +3
Misses 792 792
|
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
3557551
to
8984106
Compare
@@ -486,12 +486,10 @@ def visit_assignname( # pylint: disable=too-many-branches | |||
# Check names defined in class scopes | |||
elif isinstance(frame, nodes.ClassDef): | |||
if not list(frame.local_attr_ancestors(node.name)): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wondering if this line can be removed π€
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, removing this line caused #9765
8984106
to
6627f42
Compare
This comment has been minimized.
This comment has been minimized.
fcd32da
to
cdae5f8
Compare
This comment has been minimized.
This comment has been minimized.
Thereβs 2 warnings in the readthedocs output that are failing the ci but unsure which file itβs coming from exactly. Seems to be 3.0/index |
I'm going to try to fix the readthedoc pipeline on main. |
Well it was due to,
It was fixed by @jacobtylerwalls in #8921, so rebasing should work, thank you Jacob :) |
cdae5f8
to
83a3503
Compare
This comment has been minimized.
This comment has been minimized.
These seem valid because the names are too long for the regex defined in that project's pylintrc: import re
>>> re.match("([A-Za-z_][A-Za-z0-9_]{2,30}|(__.__))$", "registerOutputSubformatExtensions")
>>>
>>> re.match("([A-Za-z_][A-Za-z0-9_]{2,30}|(__.__))$", "registerOutputSubformatExtensio")
<re.Match object; span=(0, 31), match='registerOutputSubformatExtensio'>
>>> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would mean we never raise on an enum ? In the example with color and rgb the color is a three ints tuple and red/green/blue is simply an int maybe it's something to explore ?
@Pierre-Sassoulas in the context of the example you refer to, the message doesn't raise and that is the expected outcome since the members satisfy the checker and the attributes are not assigned values (hence they don't appear in the from enum import Enum
class AnEnum(Enum):
apple: int
PEAR: int = 42
print(AnEnum.__members__)
{'PEAR': <AnEnum.PEAR: 42>} Let's add a lower-cased from enum import Enum
class Color(Enum):
"""Represents colors as (red, green, blue) tuples."""
YELLOW = 250, 250, 0
KHAKI = 250, 250, 125
MAGENTA = 250, 0, 250
VIOLET = 250, 125, 250
CYAN = 0, 250, 250
AQUAMARINE = 125, 250, 250
purple = 1, 2, 3
# Class constant name "red" doesn't conform to UPPER_CASE naming style (invalid-name)
# Class constant name "green" doesn't conform to UPPER_CASE naming style (invalid-name)
# Class constant name "blue" doesn't conform to UPPER_CASE naming style (invalid-name)
red: int
green: int
blue: int
def __init__(self, red: int, green: int, blue: int) -> None:
self.red = red
self.green = green
self.blue = blue
@property
def as_hex(self) -> str:
"""Get hex 'abcdef' representation for a color."""
return f'{self.red:0{2}x}{self.green:0{2}x}{self.blue:0{2}x}'
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right my bad didn't see that the functional test was actually raising here. Could you add the rgb example as a functional test ? LGTM otherwise.
Unittests will fail now until pylint-dev/astroid#2263 is released. |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I liked your own functional test too, we can have both :) otherwise LGTM
Is it a bug fix il astroid ? If so we can backport it. If not let's release this in 3.0 |
It's a bug-fix in both astroid and Pylint (if I've understood you correctly :)) |
No worries - less is more :) |
Blocked by the releease of astroid 2.15.7 then ? |
It's also blocked by #8897 since the code in that example when run with the Pylint code of the current MR crashes π’ |
But I may have a fix for that shortly :) |
β¦ontainer before doing the ``invalid-name`` check. Refs pylint-dev#7402
e3b50e0
to
03329f1
Compare
π€ Effect of this PR on checked open source code: π€ Effect on home-assistant:
Effect on music21:
Effect on django:
This comment was generated for commit 03329f1 |
@mbyrnepr2 do you know why tests are passing without your astroid changes here? π |
I think the changes from astroid were pulled in from latest push? 2.15.7 astroid went out last month I think. Thereβs been a couple of different enum changes. |
2.15.7 went out yesterday, and we haven't updated pylint to that or created a new astroid pre-release (but hoping to do so soon) |
Ooh, Pierre is doing the pre-release right now! |
We have both 2.15.7 and 3.0.0b0 released now, so it should be possible to merge on main then backport. |
Type of Changes
Description
Check that a name exists inside an
enum.Enum
class'__members__
container before doing theinvalid-name
check.Refs #7402