Skip to content

Commit b44bac3

Browse files
authored
Allow UPath.lstat (#271)
* tests: UPath.lstat returns but throws warning * upath: fix lstat tests
1 parent 5f70444 commit b44bac3

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

upath/core.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -745,16 +745,15 @@ def stat( # type: ignore[override]
745745
) -> UPathStatResult:
746746
if not follow_symlinks:
747747
warnings.warn(
748-
"UPath.stat(follow_symlinks=False): follow_symlinks=False is"
749-
" currently ignored.",
748+
f"{type(self).__name__}.stat(follow_symlinks=False):"
749+
" is currently ignored.",
750750
UserWarning,
751751
stacklevel=2,
752752
)
753753
return UPathStatResult.from_info(self.fs.stat(self.path))
754754

755755
def lstat(self) -> UPathStatResult: # type: ignore[override]
756-
# return self.stat(follow_symlinks=False)
757-
raise NotImplementedError
756+
return self.stat(follow_symlinks=False)
758757

759758
def exists(self, *, follow_symlinks=True) -> bool:
760759
return self.fs.exists(self.path)

upath/implementations/http.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ def is_dir(self):
6161
def stat(self, follow_symlinks: bool = True):
6262
if not follow_symlinks:
6363
warnings.warn(
64-
"HTTPPath.stat(follow_symlinks=False): follow_symlinks=False is"
65-
" currently ignored.",
64+
f"{type(self).__name__}.stat(follow_symlinks=False):"
65+
" is currently ignored.",
6666
UserWarning,
6767
stacklevel=2,
6868
)

upath/tests/cases.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,9 @@ def test_lchmod(self):
181181
self.path.lchmod(mode=77)
182182

183183
def test_lstat(self):
184-
with pytest.raises(NotImplementedError):
185-
self.path.lstat()
184+
with pytest.warns(UserWarning, match=r"[A-Za-z]+.stat"):
185+
st = self.path.lstat()
186+
assert st is not None
186187

187188
def test_mkdir(self):
188189
new_dir = self.path.joinpath("new_dir")

0 commit comments

Comments
 (0)