2121from functools import wraps
2222from io import BytesIO , StringIO
2323from math import isinf , isnan
24- from typing import Any , Dict , List , Literal , Optional , Union
24+ from typing import (
25+ TYPE_CHECKING ,
26+ Any ,
27+ Callable ,
28+ Dict ,
29+ List ,
30+ Literal ,
31+ Optional ,
32+ TypeVar ,
33+ Union ,
34+ )
2535from warnings import warn
2636
2737from xlsxwriter .chart import Chart
5262)
5363from .xmlwriter import XMLwriter
5464
65+ if TYPE_CHECKING :
66+ from typing_extensions import Concatenate , ParamSpec , Protocol , overload
67+
68+ ReturnTypeT_co = TypeVar ("ReturnTypeT_co" , covariant = True )
69+ P = ParamSpec ("P" )
70+
71+ class CellMethod (Protocol [P , ReturnTypeT_co ]):
72+ """Overloads to support cell notation."""
73+
74+ @overload
75+ def __call__ (
76+ self , row : int , col : int , / , * args : P .args , ** kwargs : P .kwargs
77+ ) -> ReturnTypeT_co : ...
78+
79+ @overload
80+ def __call__ (
81+ self , cell : str , / , * args : P .args , ** kwargs : P .kwargs
82+ ) -> ReturnTypeT_co : ...
83+
84+ class RangeMethod (Protocol [P , ReturnTypeT_co ]):
85+ """Overloads to support range notation."""
86+
87+ @overload
88+ def __call__ (
89+ self ,
90+ first_row : int ,
91+ first_col : int ,
92+ last_row : int ,
93+ last_col : int ,
94+ / ,
95+ * args : P .args ,
96+ ** kwargs : P .kwargs ,
97+ ) -> ReturnTypeT_co : ...
98+
99+ @overload
100+ def __call__ (
101+ self , cell_range : str , / , * args : P .args , ** kwargs : P .kwargs
102+ ) -> ReturnTypeT_co : ...
103+
104+ class ColumnMethod (Protocol [P , ReturnTypeT_co ]):
105+ """Overloads to support column range notation."""
106+
107+ @overload
108+ def __call__ (
109+ self , first_col : int , last_col : int , / , * args : P .args , ** kwargs : P .kwargs
110+ ) -> ReturnTypeT_co : ...
111+
112+ @overload
113+ def __call__ (
114+ self , col_range : str , / , * args : P .args , ** kwargs : P .kwargs
115+ ) -> ReturnTypeT_co : ...
116+
117+
55118re_dynamic_function = re .compile (
56119 r"""
57120 \bANCHORARRAY\( |
92155# Decorator functions.
93156#
94157###############################################################################
95- def convert_cell_args (method ):
158+ def convert_cell_args (
159+ method : "Callable[Concatenate[Any, int, int, P], ReturnTypeT_co]" ,
160+ ) -> "CellMethod[P, ReturnTypeT_co]" :
96161 """
97162 Decorator function to convert A1 notation in cell method calls
98163 to the default row/col notation.
@@ -116,7 +181,9 @@ def cell_wrapper(self, *args, **kwargs):
116181 return cell_wrapper
117182
118183
119- def convert_range_args (method ):
184+ def convert_range_args (
185+ method : "Callable[Concatenate[Any, int, int, int, int, P], ReturnTypeT_co]" ,
186+ ) -> "RangeMethod[P, ReturnTypeT_co]" :
120187 """
121188 Decorator function to convert A1 notation in range method calls
122189 to the default row/col notation.
@@ -148,7 +215,9 @@ def cell_wrapper(self, *args, **kwargs):
148215 return cell_wrapper
149216
150217
151- def convert_column_args (method ):
218+ def convert_column_args (
219+ method : "Callable[Concatenate[Any, int, int, P], ReturnTypeT_co]" ,
220+ ) -> "ColumnMethod[P, ReturnTypeT_co]" :
152221 """
153222 Decorator function to convert A1 notation in columns method calls
154223 to the default row/col notation.
0 commit comments