Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion typer/_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,16 @@
Union,
)

from typing_extensions import Literal, get_args, get_origin
if sys.version_info >= (3, 9):
from typing import Annotated, Literal, get_args, get_origin, get_type_hints
else:
from typing_extensions import (
Annotated,
Literal,
get_args,
get_origin,
get_type_hints,
)

if sys.version_info < (3, 10):

Expand All @@ -34,6 +43,11 @@ def is_union(tp: Optional[Type[Any]]) -> bool:
"is_literal_type",
"all_literal_values",
"is_union",
"Annotated",
"Literal",
"get_args",
"get_origin",
"get_type_hints",
)


Expand Down
5 changes: 1 addition & 4 deletions typer/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@
import click.types
import click.utils

if sys.version_info >= (3, 8):
from typing import Literal
else:
from typing_extensions import Literal
from ._typing import Literal

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

Expand Down
3 changes: 1 addition & 2 deletions typer/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@
from uuid import UUID

import click
from typing_extensions import get_args, get_origin

from ._typing import is_union
from ._typing import get_args, get_origin, is_union
from .completion import get_completion_inspect_parameters
from .core import (
DEFAULT_MARKUP_MODE,
Expand Down
2 changes: 1 addition & 1 deletion typer/rich_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from rich.text import Text
from rich.theme import Theme

if sys.version_info >= (3, 8):
if sys.version_info >= (3, 9):
from typing import Literal
else:
from typing_extensions import Literal
Expand Down
3 changes: 1 addition & 2 deletions typer/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
from copy import copy
from typing import Any, Callable, Dict, List, Tuple, Type, cast

from typing_extensions import Annotated, get_args, get_origin, get_type_hints

from ._typing import Annotated, get_args, get_origin, get_type_hints
from .models import ArgumentInfo, OptionInfo, ParameterInfo, ParamMeta


Expand Down
Loading