summaryrefslogtreecommitdiff
path: root/linuxnamespaces
diff options
context:
space:
mode:
authorHelmut Grohne <helmut@subdivi.de>2024-02-21 10:15:26 +0100
committerHelmut Grohne <helmut@subdivi.de>2024-02-21 10:15:26 +0100
commitb64313d313723c62f173f750f2d699ebf169e01f (patch)
tree8af862901d1139368b3a6bac7d4bc01d27a1efe5 /linuxnamespaces
parent12f32219ff6a7e0eef6b914589d47066480404de (diff)
downloadpython-linuxnamespaces-b64313d313723c62f173f750f2d699ebf169e01f.tar.gz
revoke the false promise that bytes would be convertible to Path
pathlib.Path(somebytes) fails. Hence bytes is not actually convertible and should not be included in PathConvertible. Then, we can simplify matters in quite a few places by knowing that the thing we work with is not bytes.
Diffstat (limited to 'linuxnamespaces')
-rw-r--r--linuxnamespaces/__init__.py7
-rw-r--r--linuxnamespaces/atlocation.py10
2 files changed, 4 insertions, 13 deletions
diff --git a/linuxnamespaces/__init__.py b/linuxnamespaces/__init__.py
index c060e01..f2e54ce 100644
--- a/linuxnamespaces/__init__.py
+++ b/linuxnamespaces/__init__.py
@@ -246,11 +246,8 @@ def bind_mount(
source = AtLocation(source)
target = AtLocation(target)
try:
- # mypy does not know that os.fspath accepts AtLocation
- srcloc: str | bytes
- srcloc = os.fspath(source) # type: ignore
- tgtloc: str | bytes
- tgtloc = os.fspath(target) # type: ignore
+ srcloc = os.fspath(source)
+ tgtloc = os.fspath(target)
except ValueError:
otflags = OpenTreeFlags.OPEN_TREE_CLONE
if recursive:
diff --git a/linuxnamespaces/atlocation.py b/linuxnamespaces/atlocation.py
index 2c827a2..5871db8 100644
--- a/linuxnamespaces/atlocation.py
+++ b/linuxnamespaces/atlocation.py
@@ -17,7 +17,7 @@ import typing
AT_FDCWD = -100
-PathConvertible = typing.Union[bytes, str, os.PathLike]
+PathConvertible = typing.Union[str, os.PathLike]
class AtFlags(enum.IntFlag):
@@ -124,12 +124,6 @@ class AtLocation:
)
if not self.location:
return AtLocation(self.fd, name, self.flags)
- if isinstance(self.location, bytes) or isinstance(name, bytes):
- return AtLocation(
- self.fd,
- os.path.join(os.fsencode(self.location), os.fsencode(name)),
- self.flags,
- )
return AtLocation(
self.fd, pathlib.Path(self.location).joinpath(name), self.flags
)
@@ -344,7 +338,7 @@ class AtLocation:
"""
self.close()
- def __fspath__(self) -> str | bytes:
+ def __fspath__(self) -> str:
"""Return the underlying location if it uniquely defines this object.
Otherwise raise a ValueError.
"""