Commit Graph

146 Commits

Author SHA1 Message Date
Julien Palard 2eb503e4dd
Doc: Found some remaining default roles. (GH-98392) 2022-10-18 15:46:18 +02:00
Ansab Gillani b462f143ff
Fix documentation typo for pathlib.Path.walk (GH-96301) 2022-08-26 14:21:40 -07:00
Barney Gale 29650fea96
gh-86943: implement `pathlib.WindowsPath.is_mount()` (GH-31458)
Have `pathlib.WindowsPath.is_mount()` call `ntpath.ismount()`. Previously it raised `NotImplementedError` unconditionally.


https://bugs.python.org/issue42777
2022-08-05 15:37:44 -07:00
Stanislav Zmiev c1e929858a
gh-90385: Add `pathlib.Path.walk()` method (GH-92517)
Automerge-Triggered-By: GH:brettcannon
2022-07-22 16:55:46 -07:00
Ned Batchelder 6e2fbdab92
docs: use 'recursively' in the description of rglob, and mention globs in the os equivalences (GH-94954)
The r in `rglob` stands for "recursively", so use the word in the description. Also, glob and rglob can usefully be mentioned as the pathlib equivalent of os.walk.

Automerge-Triggered-By: GH:brettcannon
2022-07-20 14:47:43 -07:00
Chris Adams 3789c63577
Add additional pointers to pathlib's mapping to os.path functions (#94828)
* Add additional pointers to pathlib's mapping to os.path functions

os.path.splitext has a somewhat quirky signature since it mixes the path and filename components but I wanted the documentation to mention `PurePath.stem` as the natural counterpart to `PurePath.suffix` for the common use of `os.path.splitext` to turn "file.py" into "file" and "py".

Technically this could have some discussion of how to handle the parent directory hierarchy but that seems a bit out of keeping with the spirit of this table so I omitted mentioning `PurePath.parents` here.

* Update Doc/library/pathlib.rst

Co-authored-by: Ezio Melotti <ezio.melotti@gmail.com>

Co-authored-by: Ezio Melotti <ezio.melotti@gmail.com>
2022-07-16 00:09:27 +02:00
Oleg Iarygin f62ff97f31
gh-93851: Fix all broken links in Doc/ (GH-93853) 2022-06-21 20:55:18 +02:00
Oleg Iarygin 78f1a43694
gh-91317: Document that Path does not collapse initial `//` (GH-32193)
Documentation for `pathlib` says:

> Spurious slashes and single dots are collapsed, but double dots ('..') are not, since this would change the meaning of a path in the face of symbolic links:

However, it omits that initial double slashes also aren't collapsed.

Later, in documentation of `PurePath.drive`, `PurePath.root`, and `PurePath.name` it mentions UNC but:

- this abbreviation says nothing to a person who is unaware about existence of UNC (Wikipedia doesn't help either by [giving a disambiguation page](https://en.wikipedia.org/wiki/UNC))
- it shows up only if a person needs to use a specific property or decides to fully learn what the module provides.

For context, see the BPO entry.
2022-06-10 15:52:36 -07:00
jacksonriley 8ef7929baf
Fix `PurePath.relative_to` links in the pathlib documentation. (GH-93268)
These are currently broken as they refer to :meth:`Path.relative_to` rather than :meth:`PurePath.relative_to`, and `relative_to` is a method on `PurePath`.
2022-06-07 11:54:16 -07:00
Brett Cannon d59b2d0441
Fix a directive in the `pathlib` docs (GH-93030) 2022-05-20 15:52:38 -07:00
Stanley f51ed04c66
gh-72073: Add Windows case in pathlib.rename (GH-93002)
#72073

https://docs.python.org/3.12/library/pathlib.html#pathlib.Path.rename
2022-05-20 15:25:39 -07:00
Serhiy Storchaka b1c4368824
Revert "gh-92550 - Fix regression in `pathlib.Path.rglob()` (GH-92583)" (GH-92598)
This reverts commit dcdf250d2d.
2022-05-11 07:14:25 +03:00
Gregory P. Smith 07b34926d3
gh-84131: Remove the deprecated pathlib.Path.link_to method. (#92505)
Co-authored-by: Barney Gale <barney.gale@gmail.com>
2022-05-10 12:31:41 -07:00
Barney Gale dcdf250d2d
gh-92550 - Fix regression in `pathlib.Path.rglob()` (GH-92583)
We could try to remedy this by taking a slice, but we then run into an issue where the empty string will match altsep on POSIX. That rabbit hole could keep getting deeper.

A proper fix for the original issue involves making pathlib's path normalisation more configurable - in this case we want to retain trailing slashes, but in other we might want to preserve `./` prefixes, or elide `../` segments when we're sure we won't encounter symlinks.

This reverts commit ea2f5bcda1.
2022-05-09 17:12:16 -07:00
Eisuke Kawashima ea2f5bcda1
bpo-22276: Change pathlib.Path.glob not to ignore trailing path separator (GH-10349)
Now pathlib.Path.glob() **only** matches directories when the pattern ends in a path separator.

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2022-04-28 12:45:03 -07:00
slateny 161dff7e10
gh-84459: Make wording more specific for Path.replace (GH-91853)
#84459
2022-04-27 15:03:03 -07:00
Matt Williams 795b365e8a
Fix typo in Path.iterdir docs (GH-31822) 2022-03-22 19:51:41 -07:00
Barney Gale 18cb2ef46c
bpo-29688: document and test `pathlib.Path.absolute()` (GH-26153)
Co-authored-by: Brett Cannon <brett@python.org>
Co-authored-by: Brian Helba <brian.helba@kitware.com>
2022-01-28 15:40:55 -08:00
Barney Gale f24e2e5464
bpo-39950: add `pathlib.Path.hardlink_to()` method that supersedes `link_to()` (GH-18909)
The argument order of `link_to()` is reversed compared to what one may expect, so:

    a.link_to(b)

Might be expected to create *a* as a link to *b*, in fact it creates *b* as a link to *a*, making it function more like a "link from". This doesn't match `symlink_to()` nor the documentation and doesn't seem to be the original author's intent.

This PR deprecates `link_to()` and introduces `hardlink_to()`, which has the same argument order as `symlink_to()`.
2021-04-23 13:48:52 -07:00
Ned Batchelder b2b6cd00c6
docs: clarify what patterns Path.glob accepts (GH-25486)
Automerge-Triggered-By: GH:Yhg1s
2021-04-20 09:45:45 -07:00
Barney Gale 3f3d82b848
bpo-39899: os.path.expanduser(): don't guess other Windows users' home directories if the basename of the current user's home directory doesn't match their username. (GH-18841)
This makes `ntpath.expanduser()` match `pathlib.Path.expanduser()` in this regard, and is more in line with `posixpath.expanduser()`'s cautious approach.

Also remove the near-duplicate implementation of `expanduser()` in pathlib, and by doing so fix a bug where KeyError could be raised when expanding another user's home directory.
2021-04-07 23:50:13 +01:00
Barney Gale 8aac1bea2e
bpo-42999: Expand and clarify pathlib.Path.link_to() documentation. (GH-24294) 2021-04-07 16:56:32 +01:00
Barney Gale abf964942f
bpo-39906: Add follow_symlinks parameter to pathlib.Path.stat() and chmod() (GH-18864) 2021-04-07 16:53:39 +01:00
Hong Xu 1459fed92c
Doc: os.path.abspath and Path.resolve are also different (GH-23276) 2021-01-20 11:20:00 +01:00
Yaroslav Pankovych 79d2e62c00
Added support for negative indexes to PurePath.parents (GH-21799)
This commit also fixes up some of the overlapping documentation changed
in bpo-35498, which added support for indexing with slices.

Fixes bpo-21041.
https://bugs.python.org/issue21041

Co-authored-by: Paul Ganssle <p.ganssle@gmail.com>
Co-authored-by: Rémi Lapeyre <remi.lapeyre@henki.fr>
2020-11-23 15:06:22 -05:00
Joshua Cannon 4520584483
bpo-35498: Added slice support to PathLib parents attribute. (GH-11165)
Added slice support to the `pathlib.Path.parents` sequence. For a `Path` `p`, slices of `p.parents` should return the same thing as slices of `tuple(p.parents)`.
2020-11-20 10:40:39 -05:00
Максим 5f22741340
bpo-23706: Add newline parameter to pathlib.Path.write_text (GH-22420) (GH-22420)
* Add _newline_ parameter to `pathlib.Path.write_text()`
* Update documentation of `pathlib.Path.write_text()`
* Add test case for `pathlib.Path.write_text()` calls with _newline_ parameter passed

Automerge-Triggered-By: GH:methane
2020-10-20 19:08:19 -07:00
Ram Rachum f97e42ef4d
bpo-40833: Clarify Path.rename doc-string regarding relative paths (GH-20554) 2020-10-03 12:52:13 +03:00
Serhiy Storchaka 306cfb3a37
bpo-40486: Specify what happens if directory content change diring iteration (GH-22025) 2020-09-04 21:19:30 +03:00
Facundo Batista a3eae43aee
Fixed comment about pathlib.link_to: it was added in 3.8, not changed. (#21851) 2020-08-13 17:33:56 -03:00
Srinivas Reddy Thatiparthy (శ్రీనివాస్ రెడ్డి తాటిపర్తి) 0eb9deb4a6
bpo-41066: Update the comparison section for os vs pathlib (GH-21261) 2020-08-13 21:52:04 +02:00
Rotuna 448325369f
bpo-23082: Better error message for PurePath.relative_to() from pathlib (GH-19611)
Co-authored-by: Sadhana Srinivasan <rotuna@Sadhanas-MBP.fritz.box>
2020-05-25 20:42:28 +01:00
Joannah Nanjekye f25fb6ebfe
bpo-39470: Indicate that ``os.makedirs`` is equivalent to ``Path.mkdir`` (GH-18216)
* Indicate os.makedirs is equivalent to Path.mkdir

* 📜🤖 Added by blurb_it.

* ignore news feed

Co-authored-by: nanjekyejoannah <joannah.nanjekye@ibm.com>
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
2020-05-04 16:47:03 -03:00
Tim Hoffmann 8aea4b3605
bpo-40148: Add PurePath.with_stem() (GH-19295)
Add PurePath.with_stem()
2020-04-19 17:29:49 +02:00
Tim Lo c12375aa0b
bpo-39285: Clarify example for PurePath.match (GH-19458)
Fixes Issue39285

The example incorrectly returned True for match.

Furthermore the example is ambiguous in its usage of PureWindowsPath.
Windows is case-insensitve, however the underlying match functionality
utilizes fnmatch.fnmatchcase.

Automerge-Triggered-By: @pitrou
2020-04-19 02:43:11 -07:00
Serhiy Storchaka db283b32e7
bpo-39567: Document audit for os.walk, os.fwalk, Path.glob and Path.rglob. (GH-18499) 2020-03-08 14:31:47 +02:00
Brett Cannon 67152d0ed6
bpo-39808: Improve docs for pathlib.Path.stat() (GH-18719) 2020-03-04 14:51:50 -08:00
Girts a01ba333af bpo-30618: add readlink to pathlib.Path (GH-8285)
This adds a "readlink" method to pathlib.Path objects that calls through
to os.readlink.


https://bugs.python.org/issue30618



Automerge-Triggered-By: @gpshead
2019-10-23 14:18:40 -07:00
Lysandros Nikolaou af636f4f91 bpo-36182: Update pathlib.Path.write_text() docs (GH-12161)
with the case of an existing file
2019-09-11 17:08:10 +02:00
hui shang 088a09af4b bpo-31163: Added return values to pathlib.Path instance's rename and replace methods. (GH-13582)
* bpo-31163: Added return values to pathlib.Path instance's rename and replace methods.
2019-09-11 14:26:49 +01:00
Hai Shi 82642a052d bpo-37689: add Path.is_relative_to() method (GH-14982) 2019-08-13 21:54:02 +02:00
‮zlohhcuB treboR d9e006bcef bpo-33123: pathlib: Add missing_ok parameter to Path.unlink (GH-6191)
Similarly to how several pathlib file creation functions have an "exists_ok" parameter, we should introduce "missing_ok" that makes removal functions not raise an exception when a file or directory is already absent.  IMHO, this should cover Path.unlink and Path.rmdir.  Note, Path.resolve() has a "strict" parameter since 3.6 that does the same thing. Naming this of this new parameter tries to be consistent with the "exists_ok" parameter as that is more explicit about what it does (as opposed to "strict").


https://bugs.python.org/issue33123
2019-05-15 15:02:11 -07:00
Julien Palard 1d4b16051f
Doc: Be explicit that Pathlib resolve was strict before 3.6. (GH-11316) 2019-05-08 17:01:11 +02:00
Joannah Nanjekye 6b5b013bcc bpo-26978: Implement pathlib.Path.link_to (Using os.link) (GH-12990) 2019-05-04 17:27:10 +02:00
Eivind Teig 537b6caa56 bpo-22062: Updated docstring and documentation for pathlib (GH-8519)
Original patch by Mike Short


https://bugs.python.org/issue22062
2019-02-11 02:47:09 -08:00
Xtreak 6f9c55d1c0 bpo-34825: Add more entries to os to pathlib reference table (GH-9608)
The added functions are as below :

| os module     | Pathlib       |
| ------------- | ------------- |
| os.chmod   | Path.chmod  |
| os.mkdir  | Path.mkdir  | 
| os.rename | Path.rename |
| os.replace | Path.replace |
| os.rmdir  | Path.rmdir |
| os.remove, os.unlink | Path.unlink |
| os.path.samefile | Path.samefile |

Thanks


https://bugs.python.org/issue34825
2018-10-05 08:24:11 -07:00
Serhiy Storchaka 0185f34ddc
bpo-33721: Make some os.path functions and pathlib.Path methods be tolerant to invalid paths. (#7695)
Such functions as os.path.exists(), os.path.lexists(), os.path.isdir(),
os.path.isfile(), os.path.islink(), and os.path.ismount() now return False
instead of raising ValueError or its subclasses UnicodeEncodeError
and UnicodeDecodeError for paths that contain characters or bytes
unrepresentative at the OS level.
2018-09-18 11:28:51 +03:00
Xtreak 5b2657fb8c bpo-34319: Clarify file handler closure in pathlib.read_text (GH-8645)
Patch by Terry Jan Reedy.
2018-08-06 15:55:03 -04:00
Stefan Otte 46dc4e34ed bpo-34329: Doc'd how to remove suffix of pathlib.Path() (GH-8655) 2018-08-03 23:49:42 +03:00
Łukasz Langa 47320a652e Document Path.is_mount(), update Misc/ACKS and Misc/NEWS (#2980) 2017-08-01 16:47:50 -07:00
Jamiel Almeida ae8750bca8 bpo-24899: Add comparison table for os.path -> pathlib (GH-1753) 2017-06-02 11:36:02 -07:00
Marco Buttu 7b2491a6aa bpo-27200: Fix pathlib, ssl, turtle and weakref doctests (GH-616) 2017-04-13 17:17:59 +03:00
Steve Dower 98eb360531 Issue #19717: Makes Path.resolve() succeed on paths that do not exist (patch by Vajrasky Kok) 2016-11-09 12:58:17 -08:00
Ned Deily bf7dcb9cd0 Remove spurious article. 2016-10-15 15:13:20 -04:00
Ned Deily 11194f7e0f Remove spurious article. 2016-10-15 15:12:03 -04:00
Berker Peksag 009bc05fdc Merge from 3.5 2016-10-01 01:07:17 +03:00
Berker Peksag 5e3677d7af Fix markup in pathlib.rst 2016-10-01 01:06:52 +03:00
Berker Peksag 50bb940ab8 Merge from 3.5 2016-10-01 01:03:01 +03:00
Berker Peksag 06a8ac0f26 Fix Path.glob() link, reported by SilentGhost 2016-10-01 01:02:39 +03:00
Zachary Ware 8ec8749a38 Closes #27722: Merge with 3.5 2016-08-09 17:10:53 -05:00
Zachary Ware 7a26da5845 Issue #27722: Fix default for touch method's 'mode' argument 2016-08-09 17:10:39 -05:00
Berker Peksag 663dacda4d Issue #27180: Merge from 3.5 2016-07-14 07:45:24 +03:00
Berker Peksag 2b8792137b Issue #27180: Clarify Path.rename() behavior on Unix systems
Patch by Evelyn Mitchell.
2016-07-14 07:44:59 +03:00
Terry Jan Reedy 4da945f361 Merge Issue #22558. 2016-06-11 15:06:08 -04:00
Terry Jan Reedy fa089b9b0b Issue #22558: Add remaining doc links to source code for Python-coded modules.
Reformat header above separator line (added if missing) to a common format.
Patch by Yoni Lavi.
2016-06-11 15:02:54 -04:00
Brett Cannon 568be63248 Issue #27186: Add os.PathLike support to pathlib.
This adds support both to pathlib.PurePath's constructor as well as
implementing __fspath__(). This removes the provisional status for
pathlib.

Initial patch by Dusty Phillips.
2016-06-10 12:20:49 -07:00
Guido van Rossum 03e6061956 Back out pathlib.Path.path attr. (Merge 3.5->3.6) 2016-05-19 13:11:17 -07:00
Guido van Rossum 387e6e3817 Back out pathlib.Path.path attr. (Merge 3.4->3.5) 2016-05-19 13:10:20 -07:00
Guido van Rossum 3d4d01f614 Back out 7e9605697dfc, 2e3c31ab586a, 759b2cecc289.
These added a path attribute to pathlib.Path objects, and docs.
Instead, we're going to use PEP 519.

(Starting in the 3.4 branch and merging forward from there since that's what I did originally.)
2016-05-19 13:00:21 -07:00
Guido van Rossum f08a308ebb Docs for issue #22570. (Merge 3.5->3.6) 2016-01-06 11:37:52 -08:00
Guido van Rossum 1469d744bc Cross-reference os.DirEntry and pathlib.Path for issue #22570. 2016-01-06 11:36:03 -08:00
Guido van Rossum 05075203c5 Add versionadded (3.4.5) to docs for issue #22570. (Merge 3.4->3.5) 2016-01-06 11:26:36 -08:00
Guido van Rossum b1360543e5 Add versionadded (3.4.5) to docs for issue #22570. 2016-01-06 11:23:31 -08:00
Guido van Rossum 406005144b Docs for issue #22570. (Merge 3.4->3.5) 2016-01-06 11:16:28 -08:00
Guido van Rossum df85946e8a Docs for issue #22570. 2016-01-06 11:15:52 -08:00
Victor Stinner 91108f049f Issue #25210: Change error message of do_richcompare()
Don't add parenthesis to type names. Add also quotes around the type names.

Before:

  TypeError: unorderable types: int() < NoneType()

After:

  TypeError: '<' not supported between instances of 'int' and 'NoneType'
2015-10-14 18:25:31 +02:00
Antoine Pitrou 8ad751e024 Close #23904: fix pathlib documentation misleadingly mentioning that bytes objects are accepted in the PurePath constructor 2015-04-12 00:08:02 +02:00
Antoine Pitrou 8d0c478601 Close #23904: fix pathlib documentation misleadingly mentioning that bytes objects are accepted in the PurePath constructor 2015-04-12 00:08:35 +02:00
Antoine Pitrou 17cba7daf5 Issue #19777: Provide a home() classmethod on Path objects.
Contributed by Victor Salgado and Mayank Tripathi.
2015-01-12 21:03:41 +01:00
Antoine Pitrou 8477ed6048 Issue #19776: Add a expanduser() method on Path objects.
Patch by Serhiy.
2014-12-30 20:54:45 +01:00
Georg Brandl ea68398355 Closes #20218: Added convenience methods read_text/write_text and read_bytes/
write_bytes to pathlib.Path objects.

Thanks to Christopher Welborn and Ram Rachum for original patches.
2014-10-01 19:12:33 +02:00
Berker Peksag 131caba074 Revert #22251 2014-09-28 00:01:55 +03:00
Berker Peksag 9c1dba2758 Revert #22251 2014-09-28 00:00:58 +03:00
Berker Peksag f7fee33104 Issue #22251: Fix ReST markup to avoid errors building docs. 2014-09-27 23:22:35 +03:00
Berker Peksag 3749404ba5 Issue #22251: Fix ReST markup to avoid errors building docs. 2014-09-27 23:21:35 +03:00
Barry Warsaw 7c549c4e64 - Issue #21539: Add a *exists_ok* argument to `Pathlib.mkdir()` to mimic
`mkdir -p` and `os.makedirs()` functionality.  When true, ignore
  FileExistsErrors.  Patch by Berker Peksag.

(With minor cleanups, additional tests, doc tweaks, etc. by Barry)

Also:

* Remove some unused imports in test_pathlib.py reported by pyflakes.
2014-08-05 11:28:12 -04:00
Antoine Pitrou 43e3d9409d Issue #19775: Add a samefile() method to pathlib Path objects.
Initial patch by Vajrasky Kok.
2014-05-13 10:50:15 +02:00
Larry Hastings 3732ed2414 Merge in all documentation changes since branching 3.4.0rc1. 2014-03-15 21:13:56 -07:00
Antoine Pitrou ef85119618 Issue #20765: Add missing documentation for PurePath.with_name() and PurePath.with_suffix(). 2014-02-25 20:33:02 +01:00
Antoine Pitrou f6abb70b48 Mention specific exceptions instead of OSError where appropriate. 2013-12-16 21:00:53 +01:00
Antoine Pitrou 0048c98fef Issue #19921: When Path.mkdir() is called with parents=True, any missing parent is created with the default permissions, ignoring the mode argument (mimicking the POSIX "mkdir -p" command).
Patch by Serhiy.
2013-12-16 20:22:37 +01:00
Eli Bendersky b6e66ebdf7 Some minor clarifications in the documentation of pathlib + inheritance diagram 2013-11-28 06:53:05 -08:00
Ned Deily c034156f26 Change pathlib documentation to use "raise" instead of "throw". 2013-11-27 14:42:55 -08:00
Serhiy Storchaka 03cc56539f Issue #19793: Improved markup for True/False constants in pathlib documentation. 2013-11-26 21:37:12 +02:00
Andrew Kuchling 7a4e2d1751 Wording changes to pathlib docs.
Only possibly-controversial change: joinpath() was described as:

  "Calling this method is equivalent to indexing the path with each of
  the *other* arguments in turn."

'Indexing' is an odd word to use, because you can't subscript Path or
PurePath objects, so I changed it to "combining".
2013-11-22 15:45:02 -05:00
Antoine Pitrou 31119e4f10 Issue #19673: Add pathlib to the stdlib as a provisional module (PEP 428). 2013-11-22 17:38:12 +01:00