Skip to content

Commit 5aa6b1b

Browse files
bibajzTinche
authored andcommitted
Refactor is_bare for py3.7-8
1 parent 51475d8 commit 5aa6b1b

File tree

1 file changed

+10
-17
lines changed

1 file changed

+10
-17
lines changed

src/cattr/_compat.py

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -161,25 +161,18 @@ def is_mapping(type):
161161
and issubclass(type.__origin__, TypingMapping)
162162
)
163163

164-
bare_list_args = List.__args__
165-
bare_seq_args = TypingSequence.__args__
166-
bare_mapping_args = TypingMapping.__args__
167-
bare_dict_args = Dict.__args__
168-
bare_mutable_seq_args = TypingMutableSequence.__args__
169-
bare_tuple_args = Tuple.__args__
164+
bare_generic_args = {
165+
List.__args__,
166+
TypingSequence.__args__,
167+
TypingMapping.__args__,
168+
Dict.__args__,
169+
TypingMutableSequence.__args__,
170+
Tuple.__args__,
171+
None, # non-parametrized containers do not have `__args__ attribute in py3.7-8
172+
}
170173

171174
def is_bare(type):
172-
# Lower-cased generics in 3.7-8 do not have `__args__` attribute.
173-
args = getattr(type, "__args__", None)
174-
return (
175-
args == bare_list_args
176-
or args == bare_seq_args
177-
or args == bare_mapping_args
178-
or args == bare_dict_args
179-
or args == bare_mutable_seq_args
180-
or args == bare_tuple_args
181-
or args is None
182-
)
175+
return getattr(type, "__args__", None) in bare_generic_args
183176

184177
def is_counter(type):
185178
return (

0 commit comments

Comments
 (0)