Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit da46c4b

Browse files
BrianPughdpgeorge
authored andcommitted
pathlib: Add __rtruediv__ magic method to pathlib.Path.
MicroPython now supports this behaviour of __rtruediv__.
1 parent d4362d5 commit da46c4b

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

‎python-stdlib/pathlib/pathlib.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ def __init__(self, *segments):
4747
def __truediv__(self, other):
4848
return Path(self._path, str(other))
4949

50+
def __rtruediv__(self, other):
51+
return Path(other, self._path)
52+
5053
def __repr__(self):
5154
return f'{type(self).__name__}("{self._path}")'
5255

‎python-stdlib/pathlib/tests/test_pathlib.py‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,3 +322,14 @@ def test_with_suffix(self):
322322
self.assertTrue(Path("foo/test").with_suffix(".tar") == Path("foo/test.tar"))
323323
self.assertTrue(Path("foo/bar.bin").with_suffix(".txt") == Path("foo/bar.txt"))
324324
self.assertTrue(Path("bar.txt").with_suffix("") == Path("bar"))
325+
326+
def test_rtruediv(self):
327+
"""Works as of micropython ea7031f"""
328+
res = "foo" / Path("bar")
329+
self.assertTrue(res == Path("foo/bar"))
330+
331+
def test_rtruediv_inplace(self):
332+
"""Works as of micropython ea7031f"""
333+
res = "foo"
334+
res /= Path("bar")
335+
self.assertTrue(res == Path("foo/bar"))

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /