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

Exclude the _ignore_ attribute from the __members__ container. #2289

Merged

Conversation

mbyrnepr2
Copy link
Member

Closes pylint-dev/pylint#9015

Type of Changes

Type
βœ“ πŸ› Bug fix
✨ New feature
πŸ”¨ Refactoring
πŸ“œ Docs

Description

Exclude the _ignore_ attribute from the __members__ container.

Closes #9015

@mbyrnepr2 mbyrnepr2 added this to the 2.15.7 milestone Sep 7, 2023
@codecov
Copy link

codecov bot commented Sep 7, 2023

Codecov Report

Merging #2289 (1f9ae72) into main (600229f) will not change coverage.
Report is 4 commits behind head on main.
The diff coverage is 100.00%.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #2289   +/-   ##
=======================================
  Coverage   92.85%   92.85%           
=======================================
  Files          94       94           
  Lines       11056    11056           
=======================================
  Hits        10266    10266           
  Misses        790      790           
Flag Coverage Ξ”
linux 92.66% <100.00%> (ΓΈ)
pypy 91.00% <100.00%> (ΓΈ)
windows 92.44% <100.00%> (ΓΈ)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Changed Coverage Ξ”
astroid/brain/brain_namedtuple_enum.py 92.98% <100.00%> (ΓΈ)

@mbyrnepr2 mbyrnepr2 marked this pull request as ready for review September 7, 2023 15:18
Copy link
Member

@Pierre-Sassoulas Pierre-Sassoulas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look like we might need to also exclude _missing_? https://docs.python.org/3/library/enum.html

@mbyrnepr2
Copy link
Member Author

mbyrnepr2 commented Sep 11, 2023

_missing_ is a class method so Pylint is already happy with that naming. What do you think @Pierre-Sassoulas ? Or am I _missing_ something πŸ˜†

Copy link
Member

@Pierre-Sassoulas Pierre-Sassoulas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸ˜„ Hmm, and what about _name_ for example ? Just stumbled upon https://docs.python.org/3/library/enum.html#supported-sunder-names (and learnt about sunder vs dunder, nice) it doesn't seem to be all functions in this case.

@mbyrnepr2
Copy link
Member Author

mbyrnepr2 commented Sep 11, 2023

_name_ and _value_ will produce no-member and protected-access for Pylint (unlike the current issue which is invalid-name). I can throw everything into the current MR or separate these cases into another MR for clarity. I guess you prefer to include these 2 in the current MR @Pierre-Sassoulas ?

from enum import Enum


class Fruit(Enum):
    APPLE = 42
    _name_ = 'test'
    _value_ = 'test'

print(Fruit.APPLE._name_)
print(Fruit.APPLE._value_)

python example.py

Traceback (most recent call last):
...
ValueError: _names_ are reserved for future Enum use

pylint example.py

E1101: Instance of 'APPLE' has no '_value_' member (no-member)
W0212: Access to a protected member _value_ of a client class (protected-access)
Instance of 'APPLE' has no '_name_' member (no-member)
Access to a protected member _name_ of a client class (protected-access)
Class constant name "_value_" doesn't conform to UPPER_CASE naming style (invalid-name)
Class constant name "_name_" doesn't conform to UPPER_CASE naming style (invalid-name)

_generate_next_value_: staticmethod
_missing_: class method
_order_: Python 2 only

@Pierre-Sassoulas
Copy link
Member

Thank you for investigating ! If I understand correctly _value_ is somewhat similar and _names_ is not ? (It seems ValueError: _names_ are reserved for future Enum use should raise an error message in pylint, but it's very specific to enums, I don't know if we should do it and what message to raise.) If that's the case we could do _ignore_ and _value_ together and _names_ later ? If not let's just do _ignore_ to not overcomplicate things.

@Pierre-Sassoulas Pierre-Sassoulas added the Enhancement ✨ Improvement to a component label Sep 11, 2023
@mbyrnepr2
Copy link
Member Author

mbyrnepr2 commented Sep 11, 2023

Ah my example made things confusing I think :)
The Python output _names_ are reserved for future Enum use is referring to sunder names in general (_names_).
Also _value_ and _name_ do produce the invalid-name so I'll see about handling that here(Fruit.APPLE._name_ and Fruit.APPLE._value_ should be expected).

ValueError: _names_ are reserved for future Enum use could be a separate issue I think.

…and ``_value_`` sunders of an Enum member value.

Refs pylint-dev/pylint#7402
ChangeLog Outdated Show resolved Hide resolved
ChangeLog Outdated Show resolved Hide resolved
Copy link
Member

@Pierre-Sassoulas Pierre-Sassoulas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great !

@Pierre-Sassoulas
Copy link
Member

Maybe we shouldn't close the pylint issue until astroid is released upgraded and we could clean-up the history and use two commits instead of a squash ? Or we can squash, I'll let you decide :)

@Pierre-Sassoulas
Copy link
Member

We actually need to squash for the backport job to work automatically

@Pierre-Sassoulas Pierre-Sassoulas merged commit 43b7f9a into pylint-dev:main Sep 12, 2023
20 checks passed
@github-actions
Copy link
Contributor

The backport to maintenance/2.15.x failed:

The process '/usr/bin/git' failed with exit code 1

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-maintenance/2.15.x maintenance/2.15.x
# Navigate to the new working tree
cd .worktrees/backport-maintenance/2.15.x
# Create a new branch
git switch --create backport-2289-to-maintenance/2.15.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 43b7f9aa249a8a40d2561736c80953d249a2f158
# Push it to GitHub
git push --set-upstream origin backport-2289-to-maintenance/2.15.x
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-maintenance/2.15.x

Then, create a pull request where the base branch is maintenance/2.15.x and the compare/head branch is backport-2289-to-maintenance/2.15.x.

@mbyrnepr2 mbyrnepr2 deleted the pylint_issue_9015_enum_ignore branch September 12, 2023 09:07
@jacobtylerwalls
Copy link
Member

Looks like this wasn't backported, so I'll move all the labels and such here and on the pylint issue. Life goes on. :D

@Pierre-Sassoulas Pierre-Sassoulas added backported Assigned once the backport is done and removed backport maintenance/2.15.x labels Feb 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backported Assigned once the backport is done Bug πŸͺ³
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pylint complains about _ignore_ in enum classes
3 participants