-
Notifications
You must be signed in to change notification settings - Fork 49
Open
Labels
triage 🕵️Investigating root causeInvestigating root cause
Description
Bug summary
Using FilePath with a relative path strips the first character of the filename in name and parts.
Reproduction
from upath.implementations.local import FilePath
from upath import UPath
fp = FilePath("relative/path.zip")
print(fp.name) # actual: "ath.zip"
print(fp.parts) # actual: ("/", "relative", "ath.zip")
up = UPath("relative/path.zip")
print(up.name) # actual: "path.zip"
print(up.parts) # actual: ("relative", "path.zip")Expected
FilePath("relative/path.zip").name == "path.zip"
FilePath("relative/path.zip").parts == ("relative", "path.zip")All relative paths affected
| Path | Expected .name |
Actual .name |
|---|---|---|
a/b.txt |
b.txt |
.txt |
./relative/path.zip |
path.zip |
ath.zip |
../parent/file.txt |
file.txt |
ile.txt |
single.txt |
single.txt |
ingle.txt |
deep/nested/path/file.doc |
file.doc |
ile.doc |
Exactly 1 character is always truncated from the filename.
Notes / hypothesis
I believe the issue is in WrappedFileSystemFlavour.split() (upath/_flavour.py).
For relative paths, parent() returns a head with a leading / while stripped_path does not, leading to an off-by-one when slicing the tail.
Example debug:
head = "/relative" # len = 9
stripped_path = "relative/path.zip"
tail = stripped_path[len(head) + 1:] # "ath.zip"
Environment
- universal-pathlib: 0.3.8
- Python: 3.12
- OS: macOS (likely affects Linux too)
Related
- PR Fix behaviour of UPath.parent and UPath.parents #529 (anchor handling changes in
split()) - Issue
.parentsreturns an empty path as the last element #525 (parent/parts issues)
Metadata
Metadata
Assignees
Labels
triage 🕵️Investigating root causeInvestigating root cause