Skip to content

Commit 9e7afc3

Browse files
committed
🐛 Fix typing & imports for python < 3.11
1 parent 8bb363d commit 9e7afc3

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

tests/test_annotated.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from enum import StrEnum, auto
1+
from enum import Enum
2+
from typing import Union
23

34
import typer
45
from typer.testing import CliRunner
@@ -84,12 +85,12 @@ class TestAnnotatedOptionAcceptsOptionalValue:
8485
def test_enum(self):
8586
app = typer.Typer()
8687

87-
class OptEnum(StrEnum):
88-
val1 = auto()
89-
val2 = auto()
88+
class OptEnum(str, Enum):
89+
val1 = "val1"
90+
val2 = "val2"
9091

9192
@app.command()
92-
def cmd(opt: Annotated[bool | OptEnum, typer.Option()] = OptEnum.val1):
93+
def cmd(opt: Annotated[Union[bool, OptEnum], typer.Option()] = OptEnum.val1):
9394
if opt is False:
9495
print("False")
9596
elif opt is True:
@@ -121,7 +122,7 @@ def test_int(self):
121122
app = typer.Typer()
122123

123124
@app.command()
124-
def cmd(opt: Annotated[bool | int, typer.Option()] = 1):
125+
def cmd(opt: Annotated[Union[bool, int], typer.Option()] = 1):
125126
print(opt)
126127

127128
result = runner.invoke(app)

typer/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -929,7 +929,7 @@ def get_click_param(
929929
else:
930930
annotation = str
931931
main_type = annotation
932-
secondary_type: type[bool] | None = None
932+
secondary_type: Union[Type[bool], None] = None
933933
is_list = False
934934
is_tuple = False
935935
parameter_type: Any = None

0 commit comments

Comments
 (0)