summaryrefslogtreecommitdiffstats
path: root/Lib/pathlib.py
Commit message (Collapse)AuthorAgeFilesLines
* gh-84538: add strict argument to pathlib.PurePath.relative_to (GH-19813)domragusa2022-10-281-15/+33
| | | | | | | | | | | | | | | | | | | | | | | By default, :meth:`pathlib.PurePath.relative_to` doesn't deal with paths that are not a direct prefix of the other, raising an exception in that instance. This change adds a *walk_up* parameter that can be set to allow for using ``..`` to calculate the relative path. example: ``` >>> p = PurePosixPath('/etc/passwd') >>> p.relative_to('/etc') PurePosixPath('passwd') >>> p.relative_to('/usr') Traceback (most recent call last): File "<stdin>", line 1, in <module> File "pathlib.py", line 940, in relative_to raise ValueError(error_message.format(str(self), str(formatted))) ValueError: '/etc/passwd' does not start with '/usr' >>> p.relative_to('/usr', strict=False) PurePosixPath('../etc/passwd') ``` https://bugs.python.org/issue40358 Automerge-Triggered-By: GH:brettcannon
* gh-94909: fix joining of absolute and relative Windows paths in pathlib ↵Barney Gale2022-08-121-33/+8
| | | | | | | | | | | | | | | | | | | | | | (GH-95450) Have pathlib use `os.path.join()` to join arguments to the `PurePath` initialiser, which fixes a minor bug when handling relative paths with drives. Previously: ```python >>> from pathlib import PureWindowsPath >>> a = 'C:/a/b' >>> b = 'C:x/y' >>> PureWindowsPath(a, b) PureWindowsPath('C:x/y') ``` Now: ```python >>> PureWindowsPath(a, b) PureWindowsPath('C:/a/b/x/y') ```
* gh-86943: implement `pathlib.WindowsPath.is_mount()` (GH-31458)Barney Gale2022-08-051-19/+2
| | | | | | Have `pathlib.WindowsPath.is_mount()` call `ntpath.ismount()`. Previously it raised `NotImplementedError` unconditionally. https://bugs.python.org/issue42777
* gh-90385: Add `pathlib.Path.walk()` method (GH-92517)Stanislav Zmiev2022-07-221-0/+43
| | | Automerge-Triggered-By: GH:brettcannon
* gh-82116: add comment explaining use of `list(scandir_it)` in pathlib. ↵Barney Gale2022-07-201-0/+4
| | | | | (GH-94939) Automerge-Triggered-By: GH:brettcannon
* gh-93654: Add module docstring to pathlib (GH-94611)Samuel Sloniker2022-07-071-0/+7
| | | Issue: gh-93654
* gh-81790: support "UNC" device paths in `ntpath.splitdrive()` (GH-91882)Barney Gale2022-06-101-64/+4
|
* gh-93156 - fix negative indexing into absolute `pathlib.PurePath().parents` ↵Barney Gale2022-06-031-0/+2
| | | | | | | | | | | (GH-93273) When a `_PathParents` object has a drive or a root, the length of the object is *one less* than than the length of `self._parts`, which resulted in an off-by-one error when `path.parents[-n]` was fed through to `self._parts[:-n - 1]`. In particular, `path.parents[-1]` was a malformed path object with spooky properties. This is addressed by adding `len(self)` to negative indices.
* gh-92550: Fix pathlib.Path.rglob() for empty pattern (GH-92604)Serhiy Storchaka2022-05-111-1/+1
|
* Revert "gh-92550 - Fix regression in `pathlib.Path.rglob()` (GH-92583)" ↵Serhiy Storchaka2022-05-111-0/+6
| | | | | (GH-92598) This reverts commit dcdf250d2de1428f7d8b4e9ecf51d2fd8200e21a.
* gh-84131: Remove the deprecated pathlib.Path.link_to method. (#92505)Gregory P. Smith2022-05-101-17/+0
| | | Co-authored-by: Barney Gale <barney.gale@gmail.com>
* gh-92550 - Fix regression in `pathlib.Path.rglob()` (GH-92583)Barney Gale2022-05-101-6/+0
| | | | | | | 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 ea2f5bcda1a392804487e6883be89fbad38a01a5.
* bpo-22276: Change pathlib.Path.glob not to ignore trailing path separator ↵Eisuke Kawashima2022-04-281-0/+6
| | | | | | | (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>
* bpo-46556: emit `DeprecationWarning` from `pathlib.Path.__enter__()` (GH-30971)Barney Gale2022-02-081-8/+11
| | | | | In Python 3.9, Path.__exit__() was made a no-op and has never been documented. Co-authored-by: Brett Cannon <brett@python.org>
* bpo-46483: Remove `__class_getitem__` from `pathlib.PurePath` (GH-30848)Nikita Sobolev2022-02-031-3/+0
| | | Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
* bpo-43012: remove `pathlib._Accessor` (GH-25701)Barney Gale2022-02-021-112/+59
| | | | | | | | | | | | | | | | Per Pitrou: > The original intent for the “accessor” thing was to have a variant that did all accesses under a filesystem tree in a race condition-free way using openat and friends. It turned out to be much too hairy to actually implement, so was entirely abandoned, but the accessor abstraction was left there. https://discuss.python.org/t/make-pathlib-extensible/3428/2 Accessors are: - Lacking any internal purpose - '_NormalAccessor' is the only implementation - Lacking any firm conceptual difference to `Path` objects themselves (inc. subclasses) - Non-public, i.e. underscore prefixed - '_Accessor' and '_NormalAccessor' - Unofficially used to implement customized `Path` objects, but once once [bpo-24132]() is addressed there will be a supported route for that. This patch preserves all existing behaviour.
* bpo-29688: document and test `pathlib.Path.absolute()` (GH-26153)Barney Gale2022-01-281-8/+3
| | | | Co-authored-by: Brett Cannon <brett@python.org> Co-authored-by: Brian Helba <brian.helba@kitware.com>
* bpo-46483: change `PurePath.__class_getitem__` to return `GenericAlias` ↵Nikita Sobolev2022-01-231-2/+2
| | | | (GH-30822)
* bpo-46316: optimize `pathlib.Path.iterdir()` (GH-30501)Barney Gale2022-01-201-3/+0
| | | | `os.listdir()` doesn't return entries for `.` or `..`, so we don't need to check for them here.
* bpo-45853: Fix misspelling and unused import in pathlib (GH-30292)andrei kulakov2021-12-301-3/+3
|
* bpo-27827: identify a greater range of reserved filename on Windows. (GH-26698)Barney Gale2021-07-281-11/+21
| | | | | | | `pathlib.PureWindowsPath.is_reserved()` now identifies as reserved filenames with trailing spaces or colons. Co-authored-by: Barney Gale <barney.gale@foundry.com> Co-authored-by: Eryk Sun <eryksun@gmail.com>
* bpo-39950: Fix deprecation warning in test for `pathlib.Path.link_to()` ↵Barney Gale2021-05-161-1/+1
| | | | (GH-26155)
* bpo-44040: Update broken link in pathlib source (GH-25905)Kevin Follstad2021-05-051-6/+6
|
* bpo-43970: Optimize Path.cwd() in pathlib by not instantiating a class ↵kfollstad2021-04-281-1/+1
| | | | unnecessarily (GH-25699)
* bpo-43757: Make pathlib use os.path.realpath() to resolve symlinks in a path ↵Barney Gale2021-04-281-95/+30
| | | | | (GH-25264) Also adds a new "strict" argument to realpath() to avoid changing the default behaviour of pathlib while sharing the implementation.
* bpo-39950: add `pathlib.Path.hardlink_to()` method that supersedes ↵Barney Gale2021-04-231-0/+15
| | | | | | | | | | | `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()`.
* bpo-35306: Avoid raising OSError from pathlib.Path.exists when passed an ↵Steve Dower2021-04-221-0/+1
| | | | invalid filename (GH-25529)
* bpo-40107: Switch to using io.open() for pathlib.Path.open() (GH-25240)Barney Gale2021-04-091-7/+3
| | | Previously we had identical behaviour but only allowed accessors to override os.open(). This change allows the override to also construct the IO wrapper as well.
* bpo-39899: os.path.expanduser(): don't guess other Windows users' home ↵Barney Gale2021-04-071-45/+6
| | | | | | | 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.
* bpo-39659: Route calls from pathlib.Path to os.getcwd() via the path ↵Barney Gale2021-04-071-4/+6
| | | | accessor (GH-18834)
* bpo-42999: Expand and clarify pathlib.Path.link_to() documentation. (GH-24294)Barney Gale2021-04-071-8/+14
|
* bpo-39906: Add follow_symlinks parameter to pathlib.Path.stat() and chmod() ↵Barney Gale2021-04-071-14/+6
| | | | (GH-18864)
* bpo-40038: pathlib: remove partial support for preserving accessor when ↵Barney Gale2021-04-071-33/+8
| | | | modifying a path (GH-19342)
* bpo-39895: Move `pathlib.Path.touch()` implementation into the path ↵Barney Gale2021-04-071-24/+18
| | | | accessor. (GH-18838)
* bpo-39924: handle missing os functions more consistently in pathlib (GH-19220)Barney Gale2021-04-061-27/+16
|
* bpo-43510: Implement PEP 597 opt-in EncodingWarning. (GH-19481)Inada Naoki2021-03-291-0/+4
| | | | | | | | | | | See [PEP 597](https://www.python.org/dev/peps/pep-0597/). * Add `-X warn_default_encoding` and `PYTHONWARNDEFAULTENCODING`. * Add EncodingWarning * Add io.text_encoding() * open(), TextIOWrapper() emits EncodingWarning when encoding is omitted and warn_default_encoding is enabled. * _pyio.TextIOWrapper() uses UTF-8 as fallback default encoding used when failed to import locale module. (used during building Python) * bz2, configparser, gzip, lzma, pathlib, tempfile modules use io.text_encoding(). * What's new entry
* Added support for negative indexes to PurePath.parents (GH-21799)Yaroslav Pankovych2020-11-231-1/+2
| | | | | | | | | | 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>
* bpo-35498: Added slice support to PathLib parents attribute. (GH-11165)Joshua Cannon2020-11-201-0/+2
| | | 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)`.
* bpo-23706: Add newline parameter to pathlib.Path.write_text (GH-22420) ↵Максим2020-10-211-2/+2
| | | | | | | | | (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
* bpo-40833: Clarify Path.rename doc-string regarding relative paths (GH-20554)Ram Rachum2020-10-031-5/+14
|
* bpo-33660: Fix PosixPath to resolve a relative path on rootDong-hee Na2020-08-271-1/+4
|
* bpo-23082: Better error message for PurePath.relative_to() from pathlib ↵Rotuna2020-05-251-1/+2
| | | | | (GH-19611) Co-authored-by: Sadhana Srinivasan <rotuna@Sadhanas-MBP.fritz.box>
* bpo-40148: Add PurePath.with_stem() (GH-19295)Tim Hoffmann2020-04-191-0/+4
| | | | Add PurePath.with_stem()
* bpo-39894: Route calls from pathlib.Path.samefile() to os.stat() via the ↵Barney Gale2020-04-171-1/+1
| | | | path accessor (GH-18836)
* bpo-39897: Remove needless `Path(self.parent)` call, which makes ↵Barney Gale2020-04-171-3/+2
| | | | `is_mount()` misbehave in `Path` subclasses. (GH-18839)
* bpo-39901: Move `pathlib.Path.owner()` and `group()` implementations into ↵Barney Gale2020-04-171-10/+16
| | | | the path accessor. (GH-18844)
* bpo-39682: make `pathlib.Path` immutable by removing (undocumented) support ↵Barney Gale2020-04-011-42/+9
| | | | | | for "closing" a path by using it as a context manager (GH-18846) Support for using a path as a context manager remains, and is now a no-op.
* bpo-39916: Use os.scandir() as context manager in Path.glob(). (GH-18880)Serhiy Storchaka2020-03-111-2/+4
|
* bpo-38894: Fix pathlib.Path.glob in the presence of symlinks and ↵Pablo Galindo2020-03-071-13/+16
| | | | | insufficient permissions (GH-18815) Co-authored-by: Matt Wozniski <mwozniski@bloomberg.net>
* bpo-39567: Add audit for os.walk(), os.fwalk(), Path.glob() and ↵Serhiy Storchaka2020-02-121-0/+2
| | | | Path.rglob(). (GH-18372)