|
7 | 7 | for more detail. |
8 | 8 | """ |
9 | 9 |
|
| 10 | +import functools |
10 | 11 | import io |
11 | | -import posixpath |
12 | | -import zipfile |
13 | 12 | import itertools |
14 | | -import contextlib |
15 | 13 | import pathlib |
| 14 | +import posixpath |
16 | 15 | import re |
17 | 16 | import stat |
18 | 17 | import sys |
| 18 | +import zipfile |
19 | 19 |
|
| 20 | +from ._functools import save_method_args |
20 | 21 | from .glob import Translator |
21 | 22 |
|
22 | | - |
23 | 23 | __all__ = ['Path'] |
24 | 24 |
|
25 | 25 |
|
@@ -86,13 +86,12 @@ class InitializedState: |
86 | 86 | Mix-in to save the initialization state for pickling. |
87 | 87 | """ |
88 | 88 |
|
| 89 | + @save_method_args |
89 | 90 | def __init__(self, *args, **kwargs): |
90 | | - self.__args = args |
91 | | - self.__kwargs = kwargs |
92 | 91 | super().__init__(*args, **kwargs) |
93 | 92 |
|
94 | 93 | def __getstate__(self): |
95 | | - return self.__args, self.__kwargs |
| 94 | + return self._saved___init__.args, self._saved___init__.kwargs |
96 | 95 |
|
97 | 96 | def __setstate__(self, state): |
98 | 97 | args, kwargs = state |
@@ -181,22 +180,27 @@ class FastLookup(CompleteDirs): |
181 | 180 | """ |
182 | 181 |
|
183 | 182 | def namelist(self): |
184 | | - with contextlib.suppress(AttributeError): |
185 | | - return self.__names |
186 | | - self.__names = super().namelist() |
187 | | - return self.__names |
| 183 | + return self._namelist |
| 184 | + |
| 185 | + @functools.cached_property |
| 186 | + def _namelist(self): |
| 187 | + return super().namelist() |
188 | 188 |
|
189 | 189 | def _name_set(self): |
190 | | - with contextlib.suppress(AttributeError): |
191 | | - return self.__lookup |
192 | | - self.__lookup = super()._name_set() |
193 | | - return self.__lookup |
| 190 | + return self._name_set_prop |
| 191 | + |
| 192 | + @functools.cached_property |
| 193 | + def _name_set_prop(self): |
| 194 | + return super()._name_set() |
194 | 195 |
|
195 | 196 |
|
196 | 197 | def _extract_text_encoding(encoding=None, *args, **kwargs): |
197 | 198 | # compute stack level so that the caller of the caller sees any warning. |
198 | 199 | is_pypy = sys.implementation.name == 'pypy' |
199 | | - stack_level = 3 + is_pypy |
| 200 | + # PyPy no longer special cased after 7.3.19 (or maybe 7.3.18) |
| 201 | + # See jaraco/zipp#143 |
| 202 | + is_old_pypi = is_pypy and sys.pypy_version_info < (7, 3, 19) |
| 203 | + stack_level = 3 + is_old_pypi |
200 | 204 | return io.text_encoding(encoding, stack_level), args, kwargs |
201 | 205 |
|
202 | 206 |
|
@@ -351,7 +355,7 @@ def open(self, mode='r', *args, pwd=None, **kwargs): |
351 | 355 | return io.TextIOWrapper(stream, encoding, *args, **kwargs) |
352 | 356 |
|
353 | 357 | def _base(self): |
354 | | - return pathlib.PurePosixPath(self.at or self.root.filename) |
| 358 | + return pathlib.PurePosixPath(self.at) if self.at else self.filename |
355 | 359 |
|
356 | 360 | @property |
357 | 361 | def name(self): |
|
0 commit comments