Skip to content

Commit

Permalink
Simplified the checks for __args__
Browse files Browse the repository at this point in the history
  • Loading branch information
agronholm committed Oct 8, 2020
1 parent 8999e8f commit 997ea93
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions typeguard/__init__.py
Expand Up @@ -301,8 +301,7 @@ def check_dict(argname: str, value, expected_type, memo: _TypeCheckMemo) -> None
format(argname, qualified_name(value)))

if expected_type is not dict:
if (hasattr(expected_type, "__args__") and
expected_type.__args__ not in (None, expected_type.__parameters__)):
if getattr(expected_type, "__args__", None) not in (None, expected_type.__parameters__):
key_type, value_type = expected_type.__args__
if key_type is not Any or value_type is not Any:
for k, v in value.items():
Expand Down Expand Up @@ -337,8 +336,7 @@ def check_list(argname: str, value, expected_type, memo: _TypeCheckMemo) -> None
format(argname, qualified_name(value)))

if expected_type is not list:
if hasattr(expected_type, "__args__") and expected_type.__args__ not in \
(None, expected_type.__parameters__):
if getattr(expected_type, "__args__", None) not in (None, expected_type.__parameters__):
value_type = expected_type.__args__[0]
if value_type is not Any:
for i, v in enumerate(value):
Expand All @@ -350,8 +348,7 @@ def check_sequence(argname: str, value, expected_type, memo: _TypeCheckMemo) ->
raise TypeError('type of {} must be a sequence; got {} instead'.
format(argname, qualified_name(value)))

if hasattr(expected_type, "__args__") and expected_type.__args__ not in \
(None, expected_type.__parameters__):
if getattr(expected_type, "__args__", None) not in (None, expected_type.__parameters__):
value_type = expected_type.__args__[0]
if value_type is not Any:
for i, v in enumerate(value):
Expand All @@ -364,8 +361,7 @@ def check_set(argname: str, value, expected_type, memo: _TypeCheckMemo) -> None:
format(argname, qualified_name(value)))

if expected_type is not set:
if hasattr(expected_type, "__args__") and expected_type.__args__ not in \
(None, expected_type.__parameters__):
if getattr(expected_type, "__args__", None) not in (None, expected_type.__parameters__):
value_type = expected_type.__args__[0]
if value_type is not Any:
for v in value:
Expand Down

0 comments on commit 997ea93

Please sign in to comment.