@@ -41,9 +41,7 @@ def get_origin(cl):
41
41
42
42
43
43
def has (cls ):
44
- return hasattr (cls , "__attrs_attrs__" ) or hasattr (
45
- cls , "__dataclass_fields__"
46
- )
44
+ return hasattr (cls , "__attrs_attrs__" ) or hasattr (cls , "__dataclass_fields__" )
47
45
48
46
49
47
def has_with_generic (cls ):
@@ -127,15 +125,12 @@ def is_annotated(_):
127
125
128
126
def is_tuple (type ):
129
127
return type in (Tuple , tuple ) or (
130
- type .__class__ is _GenericAlias
131
- and issubclass (type .__origin__ , Tuple )
128
+ type .__class__ is _GenericAlias and issubclass (type .__origin__ , Tuple )
132
129
)
133
130
134
131
def is_union_type (obj ):
135
132
return (
136
- obj is Union
137
- or isinstance (obj , _GenericAlias )
138
- and obj .__origin__ is Union
133
+ obj is Union or isinstance (obj , _GenericAlias ) and obj .__origin__ is Union
139
134
)
140
135
141
136
def is_sequence (type : Any ) -> bool :
@@ -150,14 +145,12 @@ def is_sequence(type: Any) -> bool:
150
145
151
146
def is_mutable_set (type ):
152
147
return type is set or (
153
- type .__class__ is _GenericAlias
154
- and issubclass (type .__origin__ , MutableSet )
148
+ type .__class__ is _GenericAlias and issubclass (type .__origin__ , MutableSet )
155
149
)
156
150
157
151
def is_frozenset (type ):
158
152
return type is frozenset or (
159
- type .__class__ is _GenericAlias
160
- and issubclass (type .__origin__ , FrozenSet )
153
+ type .__class__ is _GenericAlias and issubclass (type .__origin__ , FrozenSet )
161
154
)
162
155
163
156
def is_mapping (type ):
@@ -189,9 +182,7 @@ def is_counter(type):
189
182
from typing import Literal
190
183
191
184
def is_literal (type ) -> bool :
192
- return (
193
- type .__class__ is _GenericAlias and type .__origin__ is Literal
194
- )
185
+ return type .__class__ is _GenericAlias and type .__origin__ is Literal
195
186
196
187
else :
197
188
# No literals in 3.7.
@@ -252,10 +243,7 @@ def is_annotated(type) -> bool:
252
243
def is_tuple (type ):
253
244
return (
254
245
type in (Tuple , tuple )
255
- or (
256
- type .__class__ is _GenericAlias
257
- and issubclass (type .__origin__ , Tuple )
258
- )
246
+ or (type .__class__ is _GenericAlias and issubclass (type .__origin__ , Tuple ))
259
247
or (getattr (type , "__origin__" , None ) is tuple )
260
248
)
261
249
@@ -266,10 +254,7 @@ def is_union_type(obj):
266
254
267
255
return (
268
256
obj is Union
269
- or (
270
- isinstance (obj , _UnionGenericAlias )
271
- and obj .__origin__ is Union
272
- )
257
+ or (isinstance (obj , _UnionGenericAlias ) and obj .__origin__ is Union )
273
258
or isinstance (obj , UnionType )
274
259
)
275
260
@@ -314,10 +299,7 @@ def is_mutable_set(type):
314
299
type .__class__ is _GenericAlias
315
300
and issubclass (type .__origin__ , TypingMutableSet )
316
301
)
317
- or (
318
- getattr (type , "__origin__" , None )
319
- in (set , AbcMutableSet , AbcSet )
320
- )
302
+ or (getattr (type , "__origin__" , None ) in (set , AbcMutableSet , AbcSet ))
321
303
)
322
304
323
305
def is_frozenset (type ):
@@ -337,14 +319,7 @@ def is_bare(type):
337
319
338
320
def is_mapping (type ):
339
321
return (
340
- type
341
- in (
342
- TypingMapping ,
343
- Dict ,
344
- TypingMutableMapping ,
345
- dict ,
346
- AbcMutableMapping ,
347
- )
322
+ type in (TypingMapping , Dict , TypingMutableMapping , dict , AbcMutableMapping )
348
323
or (
349
324
type .__class__ is _GenericAlias
350
325
and issubclass (type .__origin__ , TypingMapping )
0 commit comments