11
11
)
12
12
import sys
13
13
from typing import (
14
+ TYPE_CHECKING ,
14
15
Any ,
15
16
Callable ,
16
17
TypeVar ,
24
25
25
26
from pandas .io .formats .console import get_console_size
26
27
28
+ if TYPE_CHECKING :
29
+ from pandas ._typing import ListLike
27
30
EscapeChars = Union [Mapping [str , str ], Iterable [str ]]
28
31
_KT = TypeVar ("_KT" )
29
32
_VT = TypeVar ("_VT" )
30
33
31
34
32
- def adjoin (space : int , * lists : list [str ], ** kwargs ) -> str :
35
+ def adjoin (space : int , * lists : list [str ], ** kwargs : Any ) -> str :
33
36
"""
34
37
Glues together two sets of strings using the amount of space requested.
35
38
The idea is to prettify.
@@ -98,7 +101,7 @@ def _adj_justify(texts: Iterable[str], max_len: int, mode: str = "right") -> lis
98
101
99
102
100
103
def _pprint_seq (
101
- seq : Sequence , _nest_lvl : int = 0 , max_seq_items : int | None = None , ** kwds
104
+ seq : ListLike , _nest_lvl : int = 0 , max_seq_items : int | None = None , ** kwds : Any
102
105
) -> str :
103
106
"""
104
107
internal. pprinter for iterables. you should probably use pprint_thing()
@@ -136,7 +139,7 @@ def _pprint_seq(
136
139
137
140
138
141
def _pprint_dict (
139
- seq : Mapping , _nest_lvl : int = 0 , max_seq_items : int | None = None , ** kwds
142
+ seq : Mapping , _nest_lvl : int = 0 , max_seq_items : int | None = None , ** kwds : Any
140
143
) -> str :
141
144
"""
142
145
internal. pprinter for iterables. you should probably use pprint_thing()
@@ -167,7 +170,7 @@ def _pprint_dict(
167
170
168
171
169
172
def pprint_thing (
170
- thing : Any ,
173
+ thing : object ,
171
174
_nest_lvl : int = 0 ,
172
175
escape_chars : EscapeChars | None = None ,
173
176
default_escapes : bool = False ,
@@ -225,7 +228,10 @@ def as_escaped_string(
225
228
)
226
229
elif is_sequence (thing ) and _nest_lvl < get_option ("display.pprint_nest_depth" ):
227
230
result = _pprint_seq (
228
- thing ,
231
+ # error: Argument 1 to "_pprint_seq" has incompatible type "object";
232
+ # expected "ExtensionArray | ndarray[Any, Any] | Index | Series |
233
+ # SequenceNotStr[Any] | range"
234
+ thing , # type: ignore[arg-type]
229
235
_nest_lvl ,
230
236
escape_chars = escape_chars ,
231
237
quote_strings = quote_strings ,
@@ -240,7 +246,7 @@ def as_escaped_string(
240
246
241
247
242
248
def pprint_thing_encoded (
243
- object , encoding : str = "utf-8" , errors : str = "replace"
249
+ object : object , encoding : str = "utf-8" , errors : str = "replace"
244
250
) -> bytes :
245
251
value = pprint_thing (object ) # get unicode representation of object
246
252
return value .encode (encoding , errors )
@@ -252,7 +258,8 @@ def enable_data_resource_formatter(enable: bool) -> None:
252
258
return
253
259
from IPython import get_ipython
254
260
255
- ip = get_ipython ()
261
+ # error: Call to untyped function "get_ipython" in typed context
262
+ ip = get_ipython () # type: ignore[no-untyped-call]
256
263
if ip is None :
257
264
# still not in IPython
258
265
return
@@ -289,7 +296,7 @@ def default_pprint(thing: Any, max_seq_items: int | None = None) -> str:
289
296
290
297
291
298
def format_object_summary (
292
- obj ,
299
+ obj : ListLike ,
293
300
formatter : Callable ,
294
301
is_justify : bool = True ,
295
302
name : str | None = None ,
@@ -525,7 +532,7 @@ def justify(self, texts: Any, max_len: int, mode: str = "right") -> list[str]:
525
532
else :
526
533
return [x .rjust (max_len ) for x in texts ]
527
534
528
- def adjoin (self , space : int , * lists , ** kwargs ) -> str :
535
+ def adjoin (self , space : int , * lists : Any , ** kwargs : Any ) -> str :
529
536
return adjoin (space , * lists , strlen = self .len , justfunc = self .justify , ** kwargs )
530
537
531
538
@@ -557,7 +564,7 @@ def justify(
557
564
self , texts : Iterable [str ], max_len : int , mode : str = "right"
558
565
) -> list [str ]:
559
566
# re-calculate padding space per str considering East Asian Width
560
- def _get_pad (t ) :
567
+ def _get_pad (t : str ) -> int :
561
568
return max_len - self .len (t ) + len (t )
562
569
563
570
if mode == "left" :
0 commit comments