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

typecheck/Enum: fix crash in Enum attributes check #6822

Merged
merged 3 commits into from Jun 6, 2022

Conversation

huwcbjones
Copy link
Contributor

Type of Changes

Type
βœ“ πŸ› Bug fix

Description

Fixes #6805 by:

  • only checking for Enum attributes when metaclass is an Enum metaclass
  • coping with a name not being returned in __new__

@coveralls
Copy link

coveralls commented Jun 3, 2022

Pull Request Test Coverage Report for Build 2444476621

  • 4 of 4 (100.0%) changed or added relevant lines in 1 file are covered.
  • 65 unchanged lines in 6 files lost coverage.
  • Overall coverage increased (+0.009%) to 95.53%

Files with Coverage Reduction New Missed Lines %
pylint/checkers/modified_iterating_checker.py 2 97.56%
pylint/config/arguments_manager.py 2 98.22%
pylint/lint/message_state_handler.py 4 96.55%
pylint/checkers/refactoring/refactoring_checker.py 12 98.39%
pylint/checkers/variables.py 22 96.61%
pylint/lint/pylinter.py 23 94.9%
Totals Coverage Status
Change from base Build 2433586834: 0.009%
Covered Lines: 16329
Relevant Lines: 17093

πŸ’› - Coveralls

@github-actions

This comment has been minimized.

Copy link
Member

@jacobtylerwalls jacobtylerwalls left a comment

Choose a reason for hiding this comment

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

Thanks for the speedy work. Needs a short release note in 2.14/full.rst

pylint/checkers/typecheck.py Show resolved Hide resolved
# Renamed in Python 3.10 to `EnumType`
return metaclass.qname() in {"enum.EnumMeta", "enum.EnumType"}
if metaclass.qname() in {"enum.EnumMeta", "enum.EnumType"}:
return not _enum_has_attribute(owner, node)
Copy link
Member

Choose a reason for hiding this comment

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

Outside the scope of this PR, since status quo, but this looks fragile against importing enum under an alias, which @DanielNoord was just looking into at pylint-dev/astroid#1587. Probably worth a follow-up issue.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah, we should probably revisit this when we bump to 2.12.

@Pierre-Sassoulas Pierre-Sassoulas added Needs backport Needs to be cherry-picked on the current patch version by a pylint's maintainer Crash πŸ’₯ A bug that makes pylint crash labels Jun 5, 2022
@Pierre-Sassoulas Pierre-Sassoulas added this to the 2.14.1 milestone Jun 5, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Jun 5, 2022

πŸ€– Effect of this PR on checked open source code: πŸ€–

Effect on pytest:
The following messages are now emitted:

  1. redefined-variable-type:
    Redefinition of ret type from str to _pytest.config.ExitCode
    https://github.com/pytest-dev/pytest/blob/main/src/_pytest/pytester.py#L1145
  2. redefined-variable-type:
    Redefinition of ret type from int to _pytest.config.ExitCode
    https://github.com/pytest-dev/pytest/blob/main/src/_pytest/pytester.py#L1429

This comment was generated for commit 6c9bcbb

@jacobtylerwalls jacobtylerwalls merged commit 72e2e2a into pylint-dev:main Jun 6, 2022
@Pierre-Sassoulas Pierre-Sassoulas added Backported and removed Needs backport Needs to be cherry-picked on the current patch version by a pylint's maintainer labels Jun 6, 2022
Pierre-Sassoulas pushed a commit that referenced this pull request Jun 6, 2022
)

Only check for Enum attributes when metaclass is an Enum metaclass
Pierre-Sassoulas pushed a commit that referenced this pull request Jun 6, 2022
)

Only check for Enum attributes when metaclass is an Enum metaclass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Backported Crash πŸ’₯ A bug that makes pylint crash
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AttributeError: 'Call' object has no attribute 'name'
5 participants