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

Enum type matching issues in pyright 1.1.363 #7922

Closed
kkom opened this issue May 15, 2024 · 2 comments
Closed

Enum type matching issues in pyright 1.1.363 #7922

kkom opened this issue May 15, 2024 · 2 comments
Labels
addressed in next version Issue is fixed and will appear in next published version bug Something isn't working regression

Comments

@kkom
Copy link

kkom commented May 15, 2024

Describe the bug

We started to see a new type error in pyright 1.1.363. When type matching against enums using a match statement under some circumstances we see a false positive lack-of-exhaustiveness error.

I imagine it's related to this change:

Fixed bug that results in incorrect type evaluation behavior within class body of an enum class when one enum member is used to define another enum member. This involved a significant rewrite of the logic involving enum symbol evaluation.

I'm not sure if our original code is sound or not – however it's certainly a very convenient pattern.

Code or Screenshots

from enum import Enum


class MyEnum(Enum):
    ONE = "one"

    def to_int(
        self,
    ) -> int:  # error: Function with declared return type "int" must return value on all code paths, "None" is incompatible with "int" (reportReturnType)
        match self:  # error: Cases within match statement do not exhaustively handle all values, Unhandled type: "MyEnum*", If exhaustive handling is not intended, add "case _: pass" (reportMatchNotExhaustive)
            case self.ONE:
                return 1

VS Code extension or command-line

pyright 1.1.363 via the CLI

@kkom kkom added the bug Something isn't working label May 15, 2024
@erictraut erictraut changed the title Enum type matching issues in pyright 1.1.363 Regression: Enum type matching issues in pyright 1.1.363 May 15, 2024
@erictraut
Copy link
Collaborator

Thanks for the bug report, and apologies for the regression.

I rewrote major portions of pyright's enum support in version 1.1.363 to accommodate some non-standard behaviors in the EnumMeta class that were previously handled incorrectly. Pyright's unit tests for enums are pretty comprehensive, but the use case in your code sample is missing from the tests. That allowed the regression to slip in unnoticed. I'll work on a fix and improve the unit tests to cover this case.

@erictraut erictraut changed the title Regression: Enum type matching issues in pyright 1.1.363 Enum type matching issues in pyright 1.1.363 May 15, 2024
@erictraut erictraut added the addressed in next version Issue is fixed and will appear in next published version label May 16, 2024
@erictraut
Copy link
Collaborator

This is addressed in pyright 1.1.364.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addressed in next version Issue is fixed and will appear in next published version bug Something isn't working regression
Projects
None yet
Development

No branches or pull requests

2 participants