|
5 | 5 | import codecs
|
6 | 6 | from collections import abc
|
7 | 7 | import dataclasses
|
| 8 | +import functools |
8 | 9 | import gzip
|
9 | 10 | from io import (
|
10 | 11 | BufferedIOBase,
|
@@ -1130,20 +1131,19 @@ def _is_binary_mode(handle: FilePath | BaseBuffer, mode: str) -> bool:
|
1130 | 1131 | )
|
1131 | 1132 |
|
1132 | 1133 |
|
1133 |
| -def _get_binary_io_classes(_cache: list[type] = []) -> tuple[type, ...]: |
| 1134 | +@functools.lru_cache |
| 1135 | +def _get_binary_io_classes() -> tuple[type, ...]: |
1134 | 1136 | """IO classes that that expect bytes"""
|
1135 |
| - if not _cache: |
1136 |
| - binary_classes: tuple[type, ...] = (BufferedIOBase, RawIOBase) |
1137 |
| - |
1138 |
| - # python-zstandard doesn't use any of the builtin base classes; instead we |
1139 |
| - # have to use the `zstd.ZstdDecompressionReader` class for isinstance checks. |
1140 |
| - # Unfortunately `zstd.ZstdDecompressionReader` isn't exposed by python-zstandard |
1141 |
| - # so we have to get it from a `zstd.ZstdDecompressor` instance. |
1142 |
| - # See also https://github.com/indygreg/python-zstandard/pull/165. |
1143 |
| - zstd = import_optional_dependency("zstandard", errors="ignore") |
1144 |
| - if zstd is not None: |
1145 |
| - with zstd.ZstdDecompressor().stream_reader(b"") as reader: |
1146 |
| - binary_classes += (type(reader),) |
1147 |
| - |
1148 |
| - _cache[:] = binary_classes |
1149 |
| - return tuple(_cache) |
| 1137 | + binary_classes: tuple[type, ...] = (BufferedIOBase, RawIOBase) |
| 1138 | + |
| 1139 | + # python-zstandard doesn't use any of the builtin base classes; instead we |
| 1140 | + # have to use the `zstd.ZstdDecompressionReader` class for isinstance checks. |
| 1141 | + # Unfortunately `zstd.ZstdDecompressionReader` isn't exposed by python-zstandard |
| 1142 | + # so we have to get it from a `zstd.ZstdDecompressor` instance. |
| 1143 | + # See also https://github.com/indygreg/python-zstandard/pull/165. |
| 1144 | + zstd = import_optional_dependency("zstandard", errors="ignore") |
| 1145 | + if zstd is not None: |
| 1146 | + with zstd.ZstdDecompressor().stream_reader(b"") as reader: |
| 1147 | + binary_classes += (type(reader),) |
| 1148 | + |
| 1149 | + return binary_classes |
0 commit comments