Skip to content
Merged
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
17 changes: 1 addition & 16 deletions odmantic/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
ODMReference,
)
from odmantic.reference import ODMReferenceInfo
from odmantic.typing import USES_OLD_TYPING_INTERFACE
from odmantic.utils import (
is_dunder,
raise_on_invalid_collection_name,
Expand All @@ -78,9 +77,6 @@
ReprArgs,
)

if USES_OLD_TYPING_INTERFACE:
from typing import _subs_tree # type: ignore # noqa


UNTOUCHED_TYPES = FunctionType, property, classmethod, staticmethod, type

Expand Down Expand Up @@ -181,18 +177,7 @@ def validate_type(type_: Type) -> Type:
type_args: Tuple[Type, ...] = getattr(type_, "__args__", ())
new_arg_types = tuple(validate_type(subtype) for subtype in type_args)
setattr(type_, "__args__", new_arg_types)
if USES_OLD_TYPING_INTERFACE:
# FIXME: there is probably a more elegant way of doing this
subs_tree = type_._subs_tree()
if type_origin is Union:
tree_hash = hash(
frozenset(subs_tree) if isinstance(subs_tree, tuple) else subs_tree
)
else:
tree_hash = hash(
subs_tree if isinstance(subs_tree, tuple) else frozenset(subs_tree)
)
setattr(type_, "__tree_hash__", tree_hash)

return type_


Expand Down
14 changes: 2 additions & 12 deletions odmantic/typing.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,10 @@
import sys
from typing import Any
from typing import Callable as TypingCallable

if sys.version_info < (3, 7):
from typing import Callable as Callable

NoArgAnyCallable = Callable[[], Any]
else:
from collections.abc import Callable as Callable
from typing import Callable as TypingCallable

NoArgAnyCallable = TypingCallable[[], Any]
NoArgAnyCallable = TypingCallable[[], Any]

if sys.version_info < (3, 8):
from typing_extensions import Literal
else:
from typing import Literal # noqa: F401


USES_OLD_TYPING_INTERFACE = sys.version_info[:3] < (3, 7, 0) # PEP 560