Skip to content
Myr

✨ Avoid the unnecessary import of `typing_extensions` in newer Python versions (#1048)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Danilo Horta · committed by GitHub · parent 9e4ef99 · Browse files · 5 files+19 added−10 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • 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>

Diff stats

5 files+19 added−10 removed

  • other:+19 added−10 removed

5 files+19 added−10 removed

modified:typer/_typing.py+15 added-1 removed
11 unmodified lines
12 Type,13 Union,14)1516from typing_extensions import Literal, get_args, get_origin16if sys.version_info >= (3, 9):17 from typing import Annotated, Literal, get_args, get_origin, get_type_hints18else:19 from typing_extensions import (20 Annotated,21 Literal,22 get_args,23 get_origin,24 get_type_hints,25 )2627if sys.version_info < (3, 10):2829 def is_union(tp: Optional[Type[Any]]) -> bool:
12 unmodified lines
42 "is_callable_type",43 "is_literal_type",44 "all_literal_values",45 "is_union",46 "Annotated",47 "Literal",48 "get_args",49 "get_origin",50 "get_type_hints",51)525354NoneType = None.__class__
59 unmodified lines
modified:typer/core.py+1 added-4 removed
24 unmodified lines
25import click.shell_completion26import click.types27import click.utils2829if sys.version_info >= (3, 8):30 from typing import Literal29from ._typing import Literal31else:32 from typing_extensions import Literal3031MarkupMode = Literal["markdown", "rich", None]3233try:
731 unmodified lines
modified:typer/main.py+1 added-2 removed
13 unmodified lines
14from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Type, Union15from uuid import UUID1617import click18from typing_extensions import get_args, get_origin1820from ._typing import is_union19from ._typing import get_args, get_origin, is_union20from .completion import get_completion_inspect_parameters21from .core import (22 DEFAULT_MARKUP_MODE,23 MarkupMode,
1115 unmodified lines
modified:typer/rich_utils.py+1 added-1 removed
20 unmodified lines
21from rich.table import Table22from rich.text import Text23from rich.theme import Theme2425if sys.version_info >= (3, 8):25if sys.version_info >= (3, 9):26 from typing import Literal27else:28 from typing_extensions import Literal29
702 unmodified lines
modified:typer/utils.py+1 added-2 removed
1 unmodified line
2import sys3from copy import copy4from typing import Any, Callable, Dict, List, Tuple, Type, cast56from typing_extensions import Annotated, get_args, get_origin, get_type_hints76from ._typing import Annotated, get_args, get_origin, get_type_hints7from .models import ArgumentInfo, OptionInfo, ParameterInfo, ParamMeta8910def _param_type_to_user_string(param_type: Type[ParameterInfo]) -> str:
180 unmodified lines