pathlib: Add __rtruediv__ magic method to pathlib.Path.

MicroPython now supports this behaviour of __rtruediv__.
pull/663/head
Brian Pugh 2023-05-19 09:10:09 -07:00 zatwierdzone przez Damien George
rodzic d4362d5cc3
commit da46c4b9f7
2 zmienionych plików z 14 dodań i 0 usunięć

Wyświetl plik

@ -47,6 +47,9 @@ class Path:
def __truediv__(self, other):
return Path(self._path, str(other))
def __rtruediv__(self, other):
return Path(other, self._path)
def __repr__(self):
return f'{type(self).__name__}("{self._path}")'

Wyświetl plik

@ -322,3 +322,14 @@ class TestPathlib(unittest.TestCase):
self.assertTrue(Path("foo/test").with_suffix(".tar") == Path("foo/test.tar"))
self.assertTrue(Path("foo/bar.bin").with_suffix(".txt") == Path("foo/bar.txt"))
self.assertTrue(Path("bar.txt").with_suffix("") == Path("bar"))
def test_rtruediv(self):
"""Works as of micropython ea7031f"""
res = "foo" / Path("bar")
self.assertTrue(res == Path("foo/bar"))
def test_rtruediv_inplace(self):
"""Works as of micropython ea7031f"""
res = "foo"
res /= Path("bar")
self.assertTrue(res == Path("foo/bar"))