Skip to content

Commit 7531572

Browse files
committed
TYP: CallableDynamicDoc
1 parent 8647298 commit 7531572

File tree

6 files changed

+71
-11
lines changed

6 files changed

+71
-11
lines changed

pandas/_config/config.py

+14-9
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,17 @@
5858
from typing import (
5959
Any,
6060
Callable,
61+
Generic,
6162
Iterable,
6263
NamedTuple,
6364
cast,
6465
)
6566
import warnings
6667

67-
from pandas._typing import F
68+
from pandas._typing import (
69+
F,
70+
T,
71+
)
6872

6973

7074
class DeprecatedOption(NamedTuple):
@@ -124,7 +128,7 @@ def _get_single_key(pat: str, silent: bool) -> str:
124128
return key
125129

126130

127-
def _get_option(pat: str, silent: bool = False):
131+
def _get_option(pat: str, silent: bool = False) -> Any:
128132
key = _get_single_key(pat, silent)
129133

130134
# walk the nested dict
@@ -164,7 +168,7 @@ def _set_option(*args, **kwargs) -> None:
164168
o.cb(key)
165169

166170

167-
def _describe_option(pat: str = "", _print_desc: bool = True):
171+
def _describe_option(pat: str = "", _print_desc: bool = True) -> str | None:
168172

169173
keys = _select_options(pat)
170174
if len(keys) == 0:
@@ -174,8 +178,8 @@ def _describe_option(pat: str = "", _print_desc: bool = True):
174178

175179
if _print_desc:
176180
print(s)
177-
else:
178-
return s
181+
return None
182+
return s
179183

180184

181185
def _reset_option(pat: str, silent: bool = False) -> None:
@@ -247,16 +251,17 @@ def __dir__(self) -> Iterable[str]:
247251
# of options, and option descriptions.
248252

249253

250-
class CallableDynamicDoc:
251-
def __init__(self, func, doc_tmpl) -> None:
254+
class CallableDynamicDoc(Generic[T]):
255+
def __init__(self, func: Callable[..., T], doc_tmpl: str) -> None:
252256
self.__doc_tmpl__ = doc_tmpl
253257
self.__func__ = func
254258

255-
def __call__(self, *args, **kwds):
259+
def __call__(self, *args, **kwds) -> T:
256260
return self.__func__(*args, **kwds)
257261

262+
# error: Signature of "__doc__" incompatible with supertype "object"
258263
@property
259-
def __doc__(self):
264+
def __doc__(self) -> str: # type: ignore[override]
260265
opts_desc = _describe_option("all", _print_desc=False)
261266
opts_list = pp_options_list(list(_registered_options.keys()))
262267
return self.__doc_tmpl__.format(opts_desc=opts_desc, opts_list=opts_list)

pandas/_libs/indexing.pyi

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from typing import Any
2+
3+
class NDFrameIndexerBase:
4+
name: str
5+
obj: Any
6+
7+
def __init__(self, name: str, obj: Any) -> None: ...
8+
@property
9+
def ndim(self) -> int: ...

pandas/_libs/json.pyi

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from typing import (
2+
Any,
3+
Callable,
4+
)
5+
6+
def dumps(
7+
obj: Any,
8+
ensure_ascii: bool = ...,
9+
double_precision: int = ...,
10+
indent: int = ...,
11+
orient: str = ...,
12+
date_unit: str = ...,
13+
iso_dates: bool = ...,
14+
default_handler: None
15+
| Callable[[Any], str | int | float | bool | list | dict | None] = ...,
16+
) -> str: ...
17+
def loads(
18+
s: str,
19+
precise_float: bool = ...,
20+
numpy: bool = ...,
21+
dtype: None = ...,
22+
labelled: bool = ...,
23+
) -> Any: ...

pandas/_libs/reduction.pyi

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from typing import Any
2+
3+
def check_result_array(obj: object, dtype: object) -> None: ...
4+
def extract_result(res: object) -> Any: ...

pandas/core/indexing.py

+16-2
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,9 @@ class _LocationIndexer(NDFrameIndexerBase):
629629
_valid_types: str
630630
axis = None
631631

632+
# sub-classes need to set _takeable
633+
_takeable: bool
634+
632635
@final
633636
def __call__(self, axis=None):
634637
# we need to return a copy of ourselves
@@ -935,7 +938,11 @@ def _getitem_lowerdim(self, tup: tuple):
935938
# is equivalent.
936939
# (see the other place where we call _handle_lowerdim_multi_index_axis0)
937940
with suppress(IndexingError):
938-
return self._handle_lowerdim_multi_index_axis0(tup)
941+
# error "_LocationIndexer" has no attribute
942+
# "_handle_lowerdim_multi_index_axis0"
943+
return self._handle_lowerdim_multi_index_axis0( # type: ignore[attr-defined]
944+
tup
945+
)
939946

940947
tup = self._validate_key_length(tup)
941948

@@ -991,7 +998,11 @@ def _getitem_nested_tuple(self, tup: tuple):
991998
# DataFrame, IndexingError is not raised when slice(None,None,None)
992999
# with one row.
9931000
with suppress(IndexingError):
994-
return self._handle_lowerdim_multi_index_axis0(tup)
1001+
# error "_LocationIndexer" has no attribute
1002+
# "_handle_lowerdim_multi_index_axis0"
1003+
return self._handle_lowerdim_multi_index_axis0( # type: ignore[attr-defined]
1004+
tup
1005+
)
9951006
elif isinstance(self.obj, ABCSeries) and any(
9961007
isinstance(k, tuple) for k in tup
9971008
):
@@ -2296,6 +2307,9 @@ class _ScalarAccessIndexer(NDFrameIndexerBase):
22962307
Access scalars quickly.
22972308
"""
22982309

2310+
# sub-classes need to set _takeable
2311+
_takeable: bool
2312+
22992313
def _convert_key(self, key):
23002314
raise AbstractMethodError(self)
23012315

pandas/io/sas/_sas.pyi

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from pandas.io.sas.sas7bdat import SAS7BDATReader
2+
3+
class Parser:
4+
def __init__(self, parser: SAS7BDATReader) -> None: ...
5+
def read(self, nrows: int) -> None: ...

0 commit comments

Comments
 (0)