Skip to content

Path refactor #2959

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/source/reference-io.rst
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,11 @@ Asynchronous path objects

.. autoclass:: Path
:members:
:inherited-members:

.. autoclass:: PosixPath

.. autoclass:: WindowsPath
Comment on lines +636 to +638
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the use case of using trio.WindowsPath or trio.PosixPath? Looking at the code, it looks like we only wrap methods from PurePath so it's not like they get more functionality (?)

I'm probably missing something trivial though. Though if it's not necessary to then I think having to put platform-specific types is weird for an exported API.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you look at the pathlib module, that's exactly what they do there. Windows and posix have very different ways of expressing a path (backslashes vs forwardslashes etc). This is making the trio path behavior just like the stdlib.

Practically, being able to make trio.Path a subclass of PurePath means it interops with all other path-derived things, and dramatically simplifies the implementation. However, you can't directly subclass PurePath... you have to subclass PureWindowsPath or PurePosixPath. And that means you need to have to concrete PosixPath and WindowsPath classes.



.. _async-file-objects:
Expand Down
2 changes: 1 addition & 1 deletion src/trio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
open_ssl_over_tcp_stream as open_ssl_over_tcp_stream,
serve_ssl_over_tcp as serve_ssl_over_tcp,
)
from ._path import Path as Path
from ._path import Path as Path, PosixPath as PosixPath, WindowsPath as WindowsPath
from ._signals import open_signal_receiver as open_signal_receiver
from ._ssl import (
NeedHandshakeError as NeedHandshakeError,
Expand Down
Loading