Skip to content

pathlib.Path.__rtruediv__ micropython incompatability. #621

Closed
@BrianPugh

Description

@BrianPugh

I wanted to add the following magic method to the pathlib.Path object:

    def __rtruediv__(self, other):
        return Path(other, self._path)

so that the following unittest would be satisfied:

    def test_rtruediv(self):
        res = "foo" / Path("bar")
        self.assertTrue(res == Path("foo/bar"))

However, I get the following stacktrace:

Traceback (most recent call last):
  File "/Users/brianpugh/.micropython/lib/unittest/__init__.py", line 392, in run_one
  File "./tests/test_pathlib.py", line 327, in test_rtruediv
TypeError: can't convert 'Path' object to str implicitly

The __rtruediv__ method never gets called, suggesting that the str.__truediv__ gets called in a way that is different than in cpython. I'm not familiar enough with cpython or micropython internals to know str's __truediv__ implementation, but something is up.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions