Skip to content

Commit b956659

Browse files
committed
Tweaks
1 parent c07c3c6 commit b956659

File tree

2 files changed

+13
-16
lines changed

2 files changed

+13
-16
lines changed

Lib/test/test_pathlib/support/local_path.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ class LocalPathInfo(pathlib.types.PathInfo):
8282
"""
8383
Simple implementation of PathInfo for a local path
8484
"""
85+
__slots__ = ('_path', '_exists', '_is_dir', '_is_file', '_is_symlink')
86+
8587
def __init__(self, path):
8688
self._path = str(path)
8789
self._exists = None
@@ -124,11 +126,11 @@ class ReadableLocalPath(pathlib.types._ReadablePath, LexicalPath):
124126
"""
125127
Simple implementation of a ReadablePath class for local filesystem paths.
126128
"""
127-
__slots__ = ('_info')
129+
__slots__ = ('info',)
128130

129131
def __init__(self, *pathsegments):
130132
super().__init__(*pathsegments)
131-
self._info = None
133+
self.info = LocalPathInfo(self)
132134

133135
def __fspath__(self):
134136
return str(self)
@@ -141,9 +143,3 @@ def iterdir(self):
141143

142144
def readlink(self):
143145
return self.with_segments(os.readlink(self))
144-
145-
@property
146-
def info(self):
147-
if self._info is None:
148-
self._info = LocalPathInfo(self)
149-
return self._info

Lib/test/test_pathlib/support/zip_path.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ class MissingZipPathInfo:
8383
"""
8484
PathInfo implementation that is used when a zip file member is missing.
8585
"""
86+
__slots__ = ()
8687

8788
def exists(self, follow_symlinks=True):
8889
return False
@@ -195,12 +196,12 @@ class ZipFileList:
195196
tree of `ZipPathInfo` objects representing the zip file members.
196197
"""
197198

198-
__slots__ = ('root', '_items')
199+
__slots__ = ('tree', '_items')
199200

200-
def __init__(self, zip_file, items):
201-
self.root = ZipPathInfo(zip_file)
201+
def __init__(self, zip_file):
202+
self.tree = ZipPathInfo(zip_file)
202203
self._items = []
203-
for item in items:
204+
for item in zip_file.filelist:
204205
self.append(item)
205206

206207
def __len__(self):
@@ -211,7 +212,7 @@ def __iter__(self):
211212

212213
def append(self, item):
213214
self._items.append(item)
214-
self.root.resolve(item.filename, create=True).zip_info = item
215+
self.tree.resolve(item.filename, create=True).zip_info = item
215216

216217

217218
class ReadableZipPath(pathlib.types._ReadablePath):
@@ -226,7 +227,7 @@ def __init__(self, *pathsegments, zip_file):
226227
self._segments = pathsegments
227228
self.zip_file = zip_file
228229
if not isinstance(zip_file.filelist, ZipFileList):
229-
zip_file.filelist = ZipFileList(zip_file, zip_file.filelist)
230+
zip_file.filelist = ZipFileList(zip_file)
230231

231232
def __hash__(self):
232233
return hash((str(self), self.zip_file))
@@ -249,8 +250,8 @@ def with_segments(self, *pathsegments):
249250

250251
@property
251252
def info(self):
252-
root = self.zip_file.filelist.root
253-
return root.resolve(str(self), follow_symlinks=False)
253+
tree = self.zip_file.filelist.tree
254+
return tree.resolve(str(self), follow_symlinks=False)
254255

255256
def __open_rb__(self, buffering=-1):
256257
info = self.info.resolve()

0 commit comments

Comments
 (0)