Skip to content

Commit ab52638

Browse files
hortasvlandegpre-commit-ci[bot]
authored
✨ Avoid the unnecessary import of typing_extensions in newer Python versions (#1048)
Co-authored-by: Sofie Van Landeghem <svlandeg@users.noreply.github.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: svlandeg <svlandeg@github.com>
1 parent 9e4ef99 commit ab52638

File tree

5 files changed

+19
-10
lines changed

5 files changed

+19
-10
lines changed

typer/_typing.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,16 @@
1313
Union,
1414
)
1515

16-
from typing_extensions import Literal, get_args, get_origin
16+
if sys.version_info >= (3, 9):
17+
from typing import Annotated, Literal, get_args, get_origin, get_type_hints
18+
else:
19+
from typing_extensions import (
20+
Annotated,
21+
Literal,
22+
get_args,
23+
get_origin,
24+
get_type_hints,
25+
)
1726

1827
if sys.version_info < (3, 10):
1928

@@ -34,6 +43,11 @@ def is_union(tp: Optional[Type[Any]]) -> bool:
3443
"is_literal_type",
3544
"all_literal_values",
3645
"is_union",
46+
"Annotated",
47+
"Literal",
48+
"get_args",
49+
"get_origin",
50+
"get_type_hints",
3751
)
3852

3953

typer/core.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,7 @@
2626
import click.types
2727
import click.utils
2828

29-
if sys.version_info >= (3, 8):
30-
from typing import Literal
31-
else:
32-
from typing_extensions import Literal
29+
from ._typing import Literal
3330

3431
MarkupMode = Literal["markdown", "rich", None]
3532

typer/main.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@
1515
from uuid import UUID
1616

1717
import click
18-
from typing_extensions import get_args, get_origin
1918

20-
from ._typing import is_union
19+
from ._typing import get_args, get_origin, is_union
2120
from .completion import get_completion_inspect_parameters
2221
from .core import (
2322
DEFAULT_MARKUP_MODE,

typer/rich_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from rich.text import Text
2323
from rich.theme import Theme
2424

25-
if sys.version_info >= (3, 8):
25+
if sys.version_info >= (3, 9):
2626
from typing import Literal
2727
else:
2828
from typing_extensions import Literal

typer/utils.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
from copy import copy
44
from typing import Any, Callable, Dict, List, Tuple, Type, cast
55

6-
from typing_extensions import Annotated, get_args, get_origin, get_type_hints
7-
6+
from ._typing import Annotated, get_args, get_origin, get_type_hints
87
from .models import ArgumentInfo, OptionInfo, ParameterInfo, ParamMeta
98

109

0 commit comments

Comments
 (0)