Skip to content

Singleton as enum doesn't work as expected #7279

@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

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy