Skip to content

Commit

Permalink
types.py - is_instance fix for Tuple[()]
Browse files Browse the repository at this point in the history
  • Loading branch information
idanmiara committed Nov 29, 2022
1 parent 26b36b7 commit 76b7df1
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion dcd/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def is_instance(value: Any, type_: Type) -> bool:
origin = extract_origin_collection(type_)
if not isinstance(value, origin):
return False
if not extract_generic(type_):
if extract_generic_no_defaults(type_) is None:
return True
if isinstance(value, tuple) and is_tuple(type_):
tuple_types = extract_generic(type_)
Expand Down Expand Up @@ -211,6 +211,15 @@ def extract_generic(type_: Type, defaults: Tuple = ()) -> tuple:
return defaults


def extract_generic_no_defaults(type_: Type) -> Union[tuple, None]:
try:
if hasattr(type_, "_special") and type_._special:
return None
return type_.__args__
except AttributeError:
return None


def is_subclass(sub_type: Type, base_type: Type) -> bool:
if is_generic_collection(sub_type):
sub_type = extract_origin_collection(sub_type)
Expand Down

0 comments on commit 76b7df1

Please sign in to comment.