| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| Expand Up | @@ -273,7 +273,7 @@ Methods and properties | |
|
|
||
| .. testsetup:: | ||
|
|
||
| from pathlib import PurePath, PurePosixPath, PureWindowsPath | ||
| from pathlib import PurePath, PurePosixPath, PureWindowsPath, Path | ||
|
|
||
| Pure paths provide the following methods and properties: | ||
|
|
||
| Expand Down Expand Up | @@ -1229,6 +1229,56 @@ call fails (for example because the path doesn't exist). | |
| .. versionchanged:: 3.10 | ||
| The *newline* parameter was added. | ||
|
|
||
| Subclassing and Extensibility | ||
| ----------------------------- | ||
|
|
||
| Both :class:`PurePath` and :class:`Path` are directly subclassable and extensible as you | ||
| see fit: | ||
|
|
||
| >>> class MyPath(Path): | ||
| ... def my_method(self, *args, **kwargs): | ||
| ... ... # Platform agnostic implementation | ||
|
|
||
| .. note:: | ||
| Unlike :class:`PurePath` or :class:`Path`, instantiating the derived | ||
| class will not generate a differently named class: | ||
|
|
||
| .. doctest:: | ||
| :pyversion: > 3.11 | ||
|
Comment thread
Copy link
Copy Markdown
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityThis is surprising to me: python docs document one version, so what is this for?
Sorry, something went wrong.
All reactions
|
||
| :skipif: is_windows | ||
|
|
||
| >>> Path('.') # On POSIX | ||
| PosixPath('.') | ||
| >>> MyPath('.') | ||
| MyPath('.') | ||
|
|
||
| Despite this, the subclass will otherwise match the class that would be | ||
| returned by the factory on your particular system type. For instance, | ||
| when instantiated on a POSIX system: | ||
|
|
||
| .. doctest:: | ||
| :pyversion: > 3.11 | ||
| :skipif: is_windows | ||
|
|
||
| >>> [Path('/dir').is_absolute, MyPath('/dir').is_absolute()] | ||
| [True, True] | ||
| >>> [Path().home().drive, MyPath().home().drive] | ||
| ['', ''] | ||
|
Comment thread
Copy link
Copy Markdown
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityA minor point: the lists here are a little bit distracting (we are looking at methods/properties, not working with lists).
Sorry, something went wrong.
All reactions
|
||
|
|
||
| However on Windows, the *same code* will instead return values which | ||
| apply to that system: | ||
|
|
||
| .. doctest:: | ||
| :pyversion: > 3.11 | ||
| :skipif: is_posix | ||
|
|
||
| >>> [Path('/dir').is_absolute(), MyPath('/dir').is_absolute()] | ||
| [False, False] | ||
| >>> [Path().home().drive, MyPath().home().drive] | ||
| ['C:', 'C:'] | ||
|
|
||
| .. versionadded:: 3.11 | ||
|
|
||
| Correspondence to tools in the :mod:`os` module | ||
| ----------------------------------------------- | ||
|
|
||
| Expand Down | ||
| Back | FazBrowse Home | New Git URL |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityOr IS_POSIX/IS_WINDOWS? I am unaware of any precedence for the naming convention here. However having the ability to skip tests depending on platform, gives one the ability to actually have sphinx doctest the code in the documentation rather than just skipping it with :: and trusting that it is correct (as is the current practice throughout much of pathlib's documentation).
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityIt doesnt really matter in this snippet that’s invisible to readers of the doc 🙂
I think lower case looks fine.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.