| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
pathlib.Path does not satisfy SimplePath under ty or pyrefly. The protocol names the joinpath and __truediv__ parameter `other`, while typeshed names Path's `key` and `*other`. Neither side is positional-only, so the typing spec requires the names to match, and they do not. Marking the parameters positional-only reflects how both members are called and lets Path satisfy the protocol. mypy passes before and after. Closes python#542
Check 3.10, the minimum supported version, rather than 3.14. ty prunes `sys.version_info` branches statically, so 3.14 left the `< (3, 11)` compat paths in _builder, env and _compat/tomllib unchecked. Exclude tests/packages, as the mypy config did. Without it ty checks the fixture packages and fails on legacy/setup.py; CI only passed because its type job pins 3.10, whose venv still seeds setuptools. Enable every rule as an error to recover some of what `strict = true` and `disallow_any_explicit` enforced. ty has no strict mode, so this is the closest available. `missing-override-decorator` stays off: `@override` needs typing_extensions before 3.12, and build takes no runtime deps for typing. Restore `__spec__.parent` in _ctx: `__package__` is deprecated and stops being set in 3.15, and the other five modules already use `__spec__.parent`. Point every suppression and workaround at its upstream issue: - astral-sh/ty#4017 for `__spec__` typed `ModuleSpec | None` - astral-sh/ty#3962 for the `warnings.showwarning` assignment - astral-sh/ty#3699 for the recursive TOMLValue alias degrading to Divergent - python/importlib_metadata#542 for `Path` failing the SimplePath protocol The SimplePath rejection is not a ty bug: pyrefly rejects it too, and the protocol's parameters are not positional-only. python/importlib_metadata#543 fixes it upstream. Add the changelog fragment the PR template requires.
|
FWIW, I wanted to do this several years ago, when I first found this bug (Path and Traversable differ only in the name of the argument for __truediv__, making them incompatible!). You can see workarounds all over repo-review, which uses Traversable heavily. I didn't make it at the time only because Python 3.7 was still supported here. I think mypy added a workaround for this, but it's a hack if so, and other type checkers have not hacked around it. This would fix it at the core: it doesn't matter what a class names the parameter to __truediv__, this is passed by position by Python. |
Sorry, something went wrong.
|
@jaraco would you have a minute to take a look at this pull request? Thank you. |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Fixes #542.
SimplePath names the joinpath and __truediv__ parameter other without marking it positional-only, so the typing spec requires an implementation to accept other=.... Typeshed names the matching pathlib.Path parameters key and *other, so Path fails the protocol under checkers that compare parameter names:
ty 0.0.59 explains it:
pyrefly 1.1.1 reports the same. mypy 2.1.0 accepts it, which is why the docstring's claim that SimplePath is "A minimal subset of pathlib.Path" has held up until now.
Adding / to both members lets Path satisfy the protocol under ty and pyrefly, and leaves mypy passing. I verified all three against importlib_metadata 9.0.0 with the parameters patched, and checked each protocol member against Path in isolation: joinpath and __truediv__ were the only failures.
ruff format, ruff check and mypy pass. tox -e py fails to collect on this branch, but it fails the same way on a pristine main checkout, so that is unrelated.
pypa/build ran into this while moving off mypy (pypa/build#1135).