You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
pathlib ABCs: add protocols for supporting types #127456
If you want to avoid adding a dependency on the typing module at runtime, you can use a similar technique to what we do with the protocol-like ABCs in collections.abc, contextlib and os:
Use ABCs for the runtime implementation
But add them to this allowlist in typing so that the typing module treats them the same way it does protocol classes:
Thanks Alex - that will be useful when/if when make PathBase and friends public, but for now I might make pathlib._types an "orphan" module that's imported by nothing else. This also lets me add type annotations for free. It's a bit similar to wsgiref.types. Do you think I'm missing a pitfall with that approach?
Activity
barneygale commentedon Nov 30, 2024
Penny for your thoughts on this @encukou :)
AlexWaygood commentedon Nov 30, 2024
If you want to avoid adding a dependency on the typing module at runtime, you can use a similar technique to what we do with the protocol-like ABCs in
collections.abc,contextlibandos:typingso that the typing module treats them the same way it does protocol classes:cpython/Lib/typing.py
Lines 1940 to 1948 in 328187c
barneygale commentedon Nov 30, 2024
Thanks Alex - that will be useful when/if when make
PathBaseand friends public, but for now I might makepathlib._typesan "orphan" module that's imported by nothing else. This also lets me add type annotations for free. It's a bit similar towsgiref.types. Do you think I'm missing a pitfall with that approach?AlexWaygood commentedon Nov 30, 2024
Oh, if that's the plan then that should be fine, yup!
Merge branch 'main' into pythongh-127456
pythonGH-127456: pathlib ABCs: remove `ParserBase.sep`
Merge branch 'main' into pythongh-127456
GH-127456: pathlib ABCs: add protocol for path parser (#127494)
pythonGH-127456: pathlib ABCs: add protocol for path parser (python#1…