Skip to content

Commit 3f2ddc6

Browse files
committed
Fix types
1 parent 2564575 commit 3f2ddc6

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

pandas/io/common.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
# to get it through `zstd.open`.
6464
try:
6565
with import_optional_dependency("zstandard").open(io.BytesIO()) as reader:
66-
_ZstdDecompressorReader = type(reader)
66+
_ZstdDecompressorReader: type | None = type(reader)
6767
except ImportError:
6868
_ZstdDecompressorReader = None
6969

@@ -1050,8 +1050,10 @@ def _is_binary_mode(handle: FilePathOrBuffer, mode: str) -> bool:
10501050
return False
10511051

10521052
# classes that expect bytes
1053-
binary_classes = (BufferedIOBase, RawIOBase)
1053+
binary_classes = [BufferedIOBase, RawIOBase]
10541054
# Zstandard doesn't use any of the builtin base classes
10551055
if _ZstdDecompressorReader is not None:
1056-
binary_classes += (_ZstdDecompressorReader,)
1057-
return isinstance(handle, binary_classes) or "b" in getattr(handle, "mode", mode)
1056+
binary_classes.append(_ZstdDecompressorReader)
1057+
is_binary_class = isinstance(handle, tuple(binary_classes))
1058+
1059+
return is_binary_class or "b" in getattr(handle, "mode", mode)

pandas/tests/io/test_common.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
import os
1313
from pathlib import Path
1414
import tempfile
15+
from typing import (
16+
Optional,
17+
cast,
18+
)
1519

1620
import pytest
1721

@@ -101,7 +105,7 @@ def test_stringify_file_and_path_like(self):
101105

102106
@pytest.mark.parametrize(
103107
"extension,expected",
104-
[("", None)]
108+
[("", cast(Optional[str], None))]
105109
+ [
106110
(f".{ext}", compression)
107111
for compression, ext in icom._compression_to_extension.items()

0 commit comments

Comments
 (0)