1
1
from functools import wraps
2
2
import inspect
3
3
from textwrap import dedent
4
+ from typing import Any , Callable , Dict , List , Optional , Tuple , Type , Union
4
5
import warnings
5
6
6
7
from pandas ._libs .properties import cache_readonly # noqa
7
8
8
9
9
10
def deprecate (
10
- name , alternative , version , alt_name = None , klass = None , stacklevel = 2 , msg = None
11
- ):
11
+ name : str ,
12
+ alternative : Callable ,
13
+ version : str ,
14
+ alt_name : Optional [str ] = None ,
15
+ klass : Optional [Type [Warning ]] = None ,
16
+ stacklevel : int = 2 ,
17
+ msg : Optional [str ] = None ,
18
+ ) -> Callable :
12
19
"""
13
20
Return a new function that emits a deprecation warning on use.
14
21
@@ -80,7 +87,12 @@ def wrapper(*args, **kwargs):
80
87
return wrapper
81
88
82
89
83
- def deprecate_kwarg (old_arg_name , new_arg_name , mapping = None , stacklevel = 2 ):
90
+ def deprecate_kwarg (
91
+ old_arg_name : str ,
92
+ new_arg_name : Optional [str ],
93
+ mapping : Optional [Union [Dict , Callable [[Any ], Any ]]] = None ,
94
+ stacklevel : int = 2 ,
95
+ ) -> Callable :
84
96
"""
85
97
Decorator to deprecate a keyword argument of a function.
86
98
@@ -200,7 +212,9 @@ def wrapper(*args, **kwargs):
200
212
return _deprecate_kwarg
201
213
202
214
203
- def rewrite_axis_style_signature (name , extra_params ):
215
+ def rewrite_axis_style_signature (
216
+ name : str , extra_params : List [Tuple [str , Any ]]
217
+ ) -> Callable :
204
218
def decorate (func ):
205
219
@wraps (func )
206
220
def wrapper (* args , ** kwargs ):
@@ -265,11 +279,11 @@ def __init__(self, *args, **kwargs):
265
279
266
280
self .params = args or kwargs
267
281
268
- def __call__ (self , func ) :
282
+ def __call__ (self , func : Callable ) -> Callable :
269
283
func .__doc__ = func .__doc__ and func .__doc__ % self .params
270
284
return func
271
285
272
- def update (self , * args , ** kwargs ):
286
+ def update (self , * args , ** kwargs ) -> None :
273
287
"""
274
288
Update self.params with supplied args.
275
289
@@ -278,18 +292,6 @@ def update(self, *args, **kwargs):
278
292
279
293
self .params .update (* args , ** kwargs )
280
294
281
- @classmethod
282
- def from_params (cls , params ):
283
- """
284
- In the case where the params is a mutable sequence (list or dictionary)
285
- and it may change before this class is called, one may explicitly use a
286
- reference to the params rather than using *args or **kwargs which will
287
- copy the values and not reference them.
288
- """
289
- result = cls ()
290
- result .params = params
291
- return result
292
-
293
295
294
296
class Appender :
295
297
"""
@@ -311,22 +313,22 @@ def my_dog(has='fleas'):
311
313
pass
312
314
"""
313
315
314
- def __init__ (self , addendum , join = "" , indents = 0 ):
316
+ def __init__ (self , addendum : Optional [ str ] , join : str = "" , indents : int = 0 ):
315
317
if indents > 0 :
316
- self .addendum = indent (addendum , indents = indents )
318
+ self .addendum = indent (addendum , indents = indents ) # type: Optional[str]
317
319
else :
318
320
self .addendum = addendum
319
321
self .join = join
320
322
321
- def __call__ (self , func ) :
323
+ def __call__ (self , func : Callable ) -> Callable :
322
324
func .__doc__ = func .__doc__ if func .__doc__ else ""
323
325
self .addendum = self .addendum if self .addendum else ""
324
326
docitems = [func .__doc__ , self .addendum ]
325
327
func .__doc__ = dedent (self .join .join (docitems ))
326
328
return func
327
329
328
330
329
- def indent (text , indents = 1 ) :
331
+ def indent (text : Optional [ str ] , indents : int = 1 ) -> str :
330
332
if not text or not isinstance (text , str ):
331
333
return ""
332
334
jointext = "" .join (["\n " ] + [" " ] * indents )
0 commit comments