11from functools import wraps
22import inspect
33from textwrap import dedent
4+ from typing import Any , Callable , Dict , List , Optional , Tuple , Type , Union
45import warnings
56
67from pandas ._libs .properties import cache_readonly # noqa
78
89
910def 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 :
1219 """
1320 Return a new function that emits a deprecation warning on use.
1421
@@ -80,7 +87,12 @@ def wrapper(*args, **kwargs):
8087 return wrapper
8188
8289
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 :
8496 """
8597 Decorator to deprecate a keyword argument of a function.
8698
@@ -200,7 +212,9 @@ def wrapper(*args, **kwargs):
200212 return _deprecate_kwarg
201213
202214
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 :
204218 def decorate (func ):
205219 @wraps (func )
206220 def wrapper (* args , ** kwargs ):
@@ -265,11 +279,11 @@ def __init__(self, *args, **kwargs):
265279
266280 self .params = args or kwargs
267281
268- def __call__ (self , func ) :
282+ def __call__ (self , func : Callable ) -> Callable :
269283 func .__doc__ = func .__doc__ and func .__doc__ % self .params
270284 return func
271285
272- def update (self , * args , ** kwargs ):
286+ def update (self , * args , ** kwargs ) -> None :
273287 """
274288 Update self.params with supplied args.
275289
@@ -278,18 +292,6 @@ def update(self, *args, **kwargs):
278292
279293 self .params .update (* args , ** kwargs )
280294
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-
293295
294296class Appender :
295297 """
@@ -311,22 +313,22 @@ def my_dog(has='fleas'):
311313 pass
312314 """
313315
314- def __init__ (self , addendum , join = "" , indents = 0 ):
316+ def __init__ (self , addendum : Optional [ str ] , join : str = "" , indents : int = 0 ):
315317 if indents > 0 :
316- self .addendum = indent (addendum , indents = indents )
318+ self .addendum = indent (addendum , indents = indents ) # type: Optional[str]
317319 else :
318320 self .addendum = addendum
319321 self .join = join
320322
321- def __call__ (self , func ) :
323+ def __call__ (self , func : Callable ) -> Callable :
322324 func .__doc__ = func .__doc__ if func .__doc__ else ""
323325 self .addendum = self .addendum if self .addendum else ""
324326 docitems = [func .__doc__ , self .addendum ]
325327 func .__doc__ = dedent (self .join .join (docitems ))
326328 return func
327329
328330
329- def indent (text , indents = 1 ) :
331+ def indent (text : Optional [ str ] , indents : int = 1 ) -> str :
330332 if not text or not isinstance (text , str ):
331333 return ""
332334 jointext = "" .join (["\n " ] + [" " ] * indents )
0 commit comments