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

Fix false positive with inference of type-annotated Enum classes. #1734

Merged
merged 1 commit into from
Aug 7, 2022

Conversation

mbyrnepr2
Copy link
Member

@mbyrnepr2 mbyrnepr2 commented Aug 7, 2022

Closes pylint-dev/pylint#7265

Steps

  • For new features or bug fixes, add a ChangeLog entry describing what your PR does.
  • Write a good description on what the PR does.

Description

Type of Changes

Type
🐛 Bug fix
✨ New feature
🔨 Refactoring
📜 Docs

Related Issue

@coveralls
Copy link

coveralls commented Aug 7, 2022

Pull Request Test Coverage Report for Build 2812103607

  • 1 of 1 (100.0%) changed or added relevant line in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 92.257%

Totals Coverage Status
Change from base Build 2805599671: 0.0%
Covered Lines: 9699
Relevant Lines: 10513

💛 - Coveralls

@mbyrnepr2 mbyrnepr2 marked this pull request as ready for review August 7, 2022 09:27
@DanielNoord DanielNoord self-requested a review August 7, 2022 12:54
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.

👍

assert inferred_member_value.value == "sweet"


@pytest.mark.parametrize("annotation, value", [("int", 42), ("bytes", b"")])
Copy link
Member

Choose a reason for hiding this comment

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

Great parametrization !

@Pierre-Sassoulas Pierre-Sassoulas merged commit 1a698ac into pylint-dev:main Aug 7, 2022
@mbyrnepr2 mbyrnepr2 deleted the pylint_7265 branch August 7, 2022 19:31
cdce8p added a commit to cdce8p/astroid that referenced this pull request Aug 16, 2022
@cdce8p
Copy link
Member

cdce8p commented Aug 16, 2022

This change causes a crash with Home Assistant. I narrowed it down to a custom Enum implementation.

from enum import Enum

class Test(Enum):
    LOADED = "loaded", True
    SETUP_ERROR = "setup_error", True

    _recoverable: bool

    def __new__(cls, value: str, recoverable: bool):
        obj = object.__new__(cls)
        obj._value_ = value
        obj._recoverable = recoverable
        return obj

    @property
    def recoverable(self) -> bool:
        """Get if the state is recoverable."""
        return self._recoverable

Remove / comment _recoverable: bool and the error goes away. Probably need to check if the AnnAssign has a value.

@mbyrnepr2
Copy link
Member Author

Thanks Marc. Will submit a patch when I get a chance today

@mbyrnepr2
Copy link
Member Author

mbyrnepr2 commented Aug 17, 2022

#1743
FYI @Pierre-Sassoulas @cdce8p

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enum values which are of type TypedDict are unsubscriptable (false positive)
5 participants