Skip to content

Enum final checking false positive in complex case #11702

Closed
@JukkaL

Description

@JukkaL

This code generates a false positive, but weirdly I can only reproduce it if the base class is defined in a different module:

from mod import E

class EE(E):  # Cannot inherit from final class "E"
    X = (0, "")
# mod.py
from enum import Enum
from typing import Optional, Type

class E(int, Enum):
    def __init__(self, _: int, x: Optional[str] = None) -> None:
        self.x = x

    def __new__(cls: Type['E'], value: int, x: Optional[str] = None) -> 'E':
        enum = int.__new__(cls, value)
        enum._value_ = value
        enum.x = x
        return enum

The code works at runtime.

This started happening as a side effect of #11247.

Marking as high priority, since this is a regression. If it seems clear that this may only happen in pretty specialized circumstances, we can perhaps lower the priority.

cc @sobolevn

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions