Skip to content

Singleton as enum doesn't work as expected #7279

Closed
@lmazuel

Description

@lmazuel

Hello,

Based on the tag in the commit e818a96 that is the merge commit of #7000, that is declared to fix #1803, the singleton scenario as described in https://www.python.org/dev/peps/pep-0484/#support-for-singleton-types-in-unions should be supported in 0.720.

However, it's still not the case:

from typing import Union
from enum import Enum

class Empty(Enum):
    token = 0
_empty = Empty.token

def func(x: Union[int, None, Empty] = _empty) -> int:

    if x is _empty:
        return 0
    elif x is None:
        return 1
    else:  # At this point typechecker knows that x can only have type int
        return x * 2

does:

singleton.py:15: error: Unsupported operand types for * ("Empty" and "int")
singleton.py:15: note: Left operand is of type "Union[int, Empty]"

Have I misunderstood something?

Thank you!

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions