Skip to content

Commit e06fbbe

Browse files
authored
TYP: handle mypy ignore in pandas/_testing (#38236)
1 parent 9b58415 commit e06fbbe

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

pandas/_testing.py

+21-21
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,17 @@
1010
from shutil import rmtree
1111
import string
1212
import tempfile
13-
from typing import Any, Callable, ContextManager, List, Optional, Type, Union, cast
13+
from typing import (
14+
Any,
15+
Callable,
16+
ContextManager,
17+
List,
18+
Optional,
19+
Tuple,
20+
Type,
21+
Union,
22+
cast,
23+
)
1424
import warnings
1525
import zipfile
1626

@@ -301,35 +311,25 @@ def write_to_compressed(compression, path, data, dest="test"):
301311
------
302312
ValueError : An invalid compression value was passed in.
303313
"""
314+
args: Tuple[Any, ...] = (data,)
315+
mode = "wb"
316+
method = "write"
317+
compress_method: Callable
318+
304319
if compression == "zip":
305320
compress_method = zipfile.ZipFile
321+
mode = "w"
322+
args = (dest, data)
323+
method = "writestr"
306324
elif compression == "gzip":
307-
# pandas\_testing.py:288: error: Incompatible types in assignment
308-
# (expression has type "Type[GzipFile]", variable has type
309-
# "Type[ZipFile]")
310-
compress_method = gzip.GzipFile # type: ignore[assignment]
325+
compress_method = gzip.GzipFile
311326
elif compression == "bz2":
312-
# pandas\_testing.py:290: error: Incompatible types in assignment
313-
# (expression has type "Type[BZ2File]", variable has type
314-
# "Type[ZipFile]")
315-
compress_method = bz2.BZ2File # type: ignore[assignment]
327+
compress_method = bz2.BZ2File
316328
elif compression == "xz":
317329
compress_method = get_lzma_file(lzma)
318330
else:
319331
raise ValueError(f"Unrecognized compression type: {compression}")
320332

321-
if compression == "zip":
322-
mode = "w"
323-
args = (dest, data)
324-
method = "writestr"
325-
else:
326-
mode = "wb"
327-
# pandas\_testing.py:302: error: Incompatible types in assignment
328-
# (expression has type "Tuple[Any]", variable has type "Tuple[Any,
329-
# Any]")
330-
args = (data,) # type: ignore[assignment]
331-
method = "write"
332-
333333
with compress_method(path, mode=mode) as f:
334334
getattr(f, method)(*args)
335335

0 commit comments

Comments
 (0)