-
-
Notifications
You must be signed in to change notification settings - Fork 671
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix UnionType handling as with Union for Optional values
- Loading branch information
Showing
3 changed files
with
71 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,38 @@ | ||
import sys | ||
from typing import Union | ||
|
||
import click | ||
|
||
if sys.version_info >= (3, 8): | ||
from typing import get_args as _get_args | ||
from typing import get_origin as _get_origin | ||
elif sys.version_info >= (3, 7): | ||
from typing_extensions import get_args as _get_args | ||
from typing_extensions import get_origin as _get_origin | ||
else: | ||
# These methods do not handle all the same details as the imported ones. | ||
# However on Python 3.6 they should be sufficient. | ||
# typer <= 0.7.0 used this implementation. | ||
|
||
def _get_origin(arg): | ||
return getattr(arg, "__origin__", None) | ||
|
||
def _get_args(arg): | ||
return getattr(arg, "__args__", None) | ||
|
||
|
||
# Assigning variables to mark them as exported with mypy | ||
get_origin = _get_origin | ||
get_args = _get_args | ||
|
||
if sys.version_info >= (3, 10): | ||
# Type ignore since mypy does not think UnionType exists | ||
from types import UnionType # type: ignore | ||
|
||
UNION_TYPES = (Union, UnionType) | ||
else: | ||
UNION_TYPES = (Union,) | ||
|
||
|
||
def _get_click_major() -> int: | ||
return int(click.__version__.split(".")[0]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters