Skip to content

Commit

Permalink
fix(type hints): move conditional typing imports into common.typing
Browse files Browse the repository at this point in the history
  • Loading branch information
binste committed Aug 15, 2023
1 parent 674e680 commit 60a9e67
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 21 deletions.
29 changes: 8 additions & 21 deletions ibis/common/patterns.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from inspect import Parameter
from itertools import chain
from typing import (
TYPE_CHECKING,
Annotated,
ForwardRef,
Generic, # noqa: F401
Expand All @@ -27,28 +26,16 @@
from ibis.common.bases import Singleton, Slotted
from ibis.common.collections import FrozenDict, RewindableIterator, frozendict
from ibis.common.dispatch import lazy_singledispatch
from ibis.common.typing import Sentinel, get_bound_typevars, get_type_params
from ibis.common.typing import (
ModuleType,
Sentinel,
UnionType,
_ClassInfo,
get_bound_typevars,
get_type_params,
)
from ibis.util import is_iterable, promote_tuple

if TYPE_CHECKING:
from types import ModuleType

if sys.version_info >= (3, 10):
from types import UnionType
from typing import TypeAlias
else:
from typing_extensions import TypeAlias

UnionType = object()


# Keep this alias in sync with unittest.case._ClassInfo
if sys.version_info >= (3, 10):
_ClassInfo: TypeAlias = type | UnionType | tuple["_ClassInfo", ...]
else:
_ClassInfo: TypeAlias = Union[type, tuple["_ClassInfo", ...]]


T_co = TypeVar("T_co", covariant=True)


Expand Down
9 changes: 9 additions & 0 deletions ibis/common/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

import sys
from itertools import zip_longest
from types import ModuleType # noqa: F401
from typing import (
Any,
Generic, # noqa: F401
Optional,
TypeVar,
Union,
get_args,
get_origin,
)
Expand All @@ -16,8 +18,15 @@

if sys.version_info >= (3, 10):
from types import UnionType
from typing import TypeAlias

# Keep this alias in sync with unittest.case._ClassInfo
_ClassInfo: TypeAlias = type | UnionType | tuple["_ClassInfo", ...]
else:
from typing_extensions import TypeAlias # noqa: TCH002

UnionType = object()
_ClassInfo: TypeAlias = Union[type, tuple["_ClassInfo", ...]]


T = TypeVar("T")
Expand Down

0 comments on commit 60a9e67

Please sign in to comment.