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

Make enum values final - fixes #11919 #11962

Merged
merged 1 commit into from
Jan 10, 2022

Commits on Jan 10, 2022

  1. Make enum values final - fixes python#11919

    This fix allows using enum values in place of literals.
    
    For example:
    
    ```
    def is_a(a: Literal["a"]): return None
    class MyStr(Enum):
        a = "a"
        b = "b"
    
    is_a(MyStr.a.value)
    ```
    
    Currently this fails with
    
    ```
    error: Argument 1 to "is_a" has incompatible type "str"; expected "Literal['a']"
    ```
    
    The fix itself is simple - the special casing of  final status for enums was being
    called too late to have an effect. Moving the function call up solves
    the problem.
    joey-laminar committed Jan 10, 2022
    Configuration menu
    Copy the full SHA
    10ccceb View commit details
    Browse the repository at this point in the history