Skip to content

Pattern matching fail when not specifying all enum values #1591 #1860

Open
@deborshi-web

Description

The code is running fine after i removing all default

from enum import Enum
from typing import Optional

def Query(any_object):
return any_object

class Environment(Enum):
DEV = "DEV"
UAT = "UAT"
TEST = "TEST"
PROD = "PROD"

class ListOut:
pass

def list_items(
usecase_id: Optional[str] = Query(None),
environment: Optional[Environment] = Query(None), #made changes in these lines
asset_id: Optional[str] = Query(None)
) -> ListOut:
match (usecase_id, environment, asset_id):
case (None, None, None):
out = ListOut()
case (uc, None, None):
out = ListOut()
case (None, e, None) if e:
out = ListOut()
case (None, None, a) if a:
out = ListOut()
case (None, e, a) if e and a:
out = ListOut()
case (u, e, None) if u and e:
out = ListOut()
case (u, None, a) if u and a:
out = ListOut()
case (uc, e, a):
out = ListOut()
return out

Origin code:
Query(default=None),
environment: Optional[Environment] = Query(default=None),
asset_id: Optional[str] = Query(default=None)

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions