36
36
is_iterator = lib .is_iterator
37
37
38
38
39
- def is_number (obj ) -> TypeGuard [Number | np .number ]:
39
+ def is_number (obj : object ) -> TypeGuard [Number | np .number ]:
40
40
"""
41
41
Check if the object is a number.
42
42
@@ -77,7 +77,7 @@ def is_number(obj) -> TypeGuard[Number | np.number]:
77
77
return isinstance (obj , (Number , np .number ))
78
78
79
79
80
- def iterable_not_string (obj ) -> bool :
80
+ def iterable_not_string (obj : object ) -> bool :
81
81
"""
82
82
Check if the object is an iterable but not a string.
83
83
@@ -102,7 +102,7 @@ def iterable_not_string(obj) -> bool:
102
102
return isinstance (obj , abc .Iterable ) and not isinstance (obj , str )
103
103
104
104
105
- def is_file_like (obj ) -> bool :
105
+ def is_file_like (obj : object ) -> bool :
106
106
"""
107
107
Check if the object is a file-like object.
108
108
@@ -138,7 +138,7 @@ def is_file_like(obj) -> bool:
138
138
return bool (hasattr (obj , "__iter__" ))
139
139
140
140
141
- def is_re (obj ) -> TypeGuard [Pattern ]:
141
+ def is_re (obj : object ) -> TypeGuard [Pattern ]:
142
142
"""
143
143
Check if the object is a regex pattern instance.
144
144
@@ -163,7 +163,7 @@ def is_re(obj) -> TypeGuard[Pattern]:
163
163
return isinstance (obj , Pattern )
164
164
165
165
166
- def is_re_compilable (obj ) -> bool :
166
+ def is_re_compilable (obj : object ) -> bool :
167
167
"""
168
168
Check if the object can be compiled into a regex pattern instance.
169
169
@@ -185,14 +185,14 @@ def is_re_compilable(obj) -> bool:
185
185
False
186
186
"""
187
187
try :
188
- re .compile (obj )
188
+ re .compile (obj ) # type: ignore[call-overload]
189
189
except TypeError :
190
190
return False
191
191
else :
192
192
return True
193
193
194
194
195
- def is_array_like (obj ) -> bool :
195
+ def is_array_like (obj : object ) -> bool :
196
196
"""
197
197
Check if the object is array-like.
198
198
@@ -224,7 +224,7 @@ def is_array_like(obj) -> bool:
224
224
return is_list_like (obj ) and hasattr (obj , "dtype" )
225
225
226
226
227
- def is_nested_list_like (obj ) -> bool :
227
+ def is_nested_list_like (obj : object ) -> bool :
228
228
"""
229
229
Check if the object is list-like, and that all of its elements
230
230
are also list-like.
@@ -265,12 +265,13 @@ def is_nested_list_like(obj) -> bool:
265
265
return (
266
266
is_list_like (obj )
267
267
and hasattr (obj , "__len__" )
268
- and len (obj ) > 0
269
- and all (is_list_like (item ) for item in obj )
268
+ # need PEP 724 to handle these typing errors
269
+ and len (obj ) > 0 # pyright: ignore[reportGeneralTypeIssues]
270
+ and all (is_list_like (item ) for item in obj ) # type: ignore[attr-defined]
270
271
)
271
272
272
273
273
- def is_dict_like (obj ) -> bool :
274
+ def is_dict_like (obj : object ) -> bool :
274
275
"""
275
276
Check if the object is dict-like.
276
277
@@ -303,7 +304,7 @@ def is_dict_like(obj) -> bool:
303
304
)
304
305
305
306
306
- def is_named_tuple (obj ) -> bool :
307
+ def is_named_tuple (obj : object ) -> bool :
307
308
"""
308
309
Check if the object is a named tuple.
309
310
@@ -331,7 +332,7 @@ def is_named_tuple(obj) -> bool:
331
332
return isinstance (obj , abc .Sequence ) and hasattr (obj , "_fields" )
332
333
333
334
334
- def is_hashable (obj ) -> TypeGuard [Hashable ]:
335
+ def is_hashable (obj : object ) -> TypeGuard [Hashable ]:
335
336
"""
336
337
Return True if hash(obj) will succeed, False otherwise.
337
338
@@ -370,7 +371,7 @@ def is_hashable(obj) -> TypeGuard[Hashable]:
370
371
return True
371
372
372
373
373
- def is_sequence (obj ) -> bool :
374
+ def is_sequence (obj : object ) -> bool :
374
375
"""
375
376
Check if the object is a sequence of objects.
376
377
String types are not included as sequences here.
@@ -394,14 +395,16 @@ def is_sequence(obj) -> bool:
394
395
False
395
396
"""
396
397
try :
397
- iter (obj ) # Can iterate over it.
398
- len (obj ) # Has a length associated with it.
398
+ # Can iterate over it.
399
+ iter (obj ) # type: ignore[call-overload]
400
+ # Has a length associated with it.
401
+ len (obj ) # type: ignore[arg-type]
399
402
return not isinstance (obj , (str , bytes ))
400
403
except (TypeError , AttributeError ):
401
404
return False
402
405
403
406
404
- def is_dataclass (item ) -> bool :
407
+ def is_dataclass (item : object ) -> bool :
405
408
"""
406
409
Checks if the object is a data-class instance
407
410
0 commit comments