The pathlib implementation seems to go to some trouble to preserve subtypes in children. This works fine: ``` python import pathlib class MyPath(pathlib.PosixPath): def parity(self): return len(str(self)) % 2 root = MyPath('/') print(root.parity()) child = root / 'there' print(child.parity()) ``` ``` $ python3 t.py 1 0 ``` But this declaration isn't parameterized: ``` python def __truediv__(self, key: Union[str, PurePath]) -> PurePath: ... ``` so the program above doesn't typecheck: ``` $ mypy t.py t.py:11: error: "PurePath" has no attribute "parity" ```
Activity
gvanrossum commentedon Sep 17, 2016
Yes, this is currently a problem. We first need to solve python/mypy#1212 and then it should be easy. See also python/peps#89
dckc commentedon Sep 17, 2016
I found a work-around:
gvanrossum commentedon Sep 17, 2016