Issue40358
Created on 2020-04-22 00:03 by d.ragusa, last changed 2022-04-11 14:59 by admin.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| relative_to.patch | d.ragusa, 2020-04-28 03:52 | |||
| Pull Requests | |||
|---|---|---|---|
| URL | Status | Linked | Edit |
| PR 19807 | closed | python-dev, 2020-04-30 00:03 | |
| PR 19813 | open | d.ragusa, 2020-04-30 10:30 | |
| Messages (11) | |||
|---|---|---|---|
| msg366958 - (view) | Author: Domenico Ragusa (d.ragusa) * | Date: 2020-04-22 00:03 | |
Can we improve pathlib.relative_to(other) so that it handles the case of a path not being a direct child of other, like os.path.relpath?
For example:
Path('/some/thing').relative_to('/foo') -> Path('../some/thing')
At the moment it just raises an exception.
|
|||
| msg367037 - (view) | Author: Antoine Pitrou (pitrou) * ![]() |
Date: 2020-04-22 18:18 | |
The current behaviour is by design. I would not mind adding an option to control it, though. If you are new to Python development and want to submit a patch or PR, I recommend reading the Developer's Guide: https://devguide.python.org/ |
|||
| msg367041 - (view) | Author: Domenico Ragusa (d.ragusa) * | Date: 2020-04-22 19:00 | |
Thanks for your answer. Yeah, I'm new, I'm reading the guide, sorry for any faux pas :) Ok, an option would be great as well, a simple True/False switch? Any suggestion for the name? I'll get back with a proper patch this time. On Wed, Apr 22, 2020 at 8:18 PM Antoine Pitrou <report@bugs.python.org> wrote: > > Antoine Pitrou <solipsis@pitrou.net> added the comment: > > The current behaviour is by design. I would not mind adding an option to > control it, though. > > If you are new to Python development and want to submit a patch or PR, I > recommend reading the Developer's Guide: > https://devguide.python.org/ > > ---------- > > _______________________________________ > Python tracker <report@bugs.python.org> > <https://bugs.python.org/issue40358> > _______________________________________ > |
|||
| msg367047 - (view) | Author: Eryk Sun (eryksun) * ![]() |
Date: 2020-04-22 19:50 | |
Note that the implementation of relpath is pure and thus assumes it's working with existing, resolved paths (i.e. "the filesystem is not accessed to confirm the existence or nature of path or start"). For example:
>>> os.path.relpath('/some/thing', '/symlink')
'../some/thing'
If "symlink" targets "/spam/eggs/foo", then the resolved path would be "/spam/eggs/some/thing" instead of "/some/thing". Maybe the relative_to method should default to a `strict` mode that raises ValueError on ambiguous cases that depend on the "existence or nature" of the paths. I think the current implementation is strict.
|
|||
| msg367490 - (view) | Author: Domenico Ragusa (d.ragusa) * | Date: 2020-04-28 03:52 | |
Yeah, you're right, there's no access to the filesystem and the result is generated assuming the paths are already resolved. `strict` seems to be an appropriate name for the option, thanks. I've looked into the test suite, it helped a lot especially with Windows paths, they were more complicated than I though. I've duplicated the tests to verify that it still function as before and I've added some tests for values that would raise an exception. It works. I'm not overly fond of the way I check for unrelated paths, but I couldn't think of something more elegant. Any input is appreciated. |
|||
| msg367697 - (view) | Author: Ammar Askar (ammar2) * ![]() |
Date: 2020-04-29 20:08 | |
Thank you for your work on this Domenico. For reviewing the code, would you mind creating a Github pull request for it as described here https://devguide.python.org/pullrequest/ |
|||
| msg367723 - (view) | Author: Domenico Ragusa (d.ragusa) * | Date: 2020-04-30 00:49 | |
I may have forgotten to use the proper format for the title of each commit, should I delete the pull request and make a new one or can it be fixed when (or if) it's pulled? On Thu, Apr 30, 2020 at 2:03 AM Roundup Robot <report@bugs.python.org> wrote: > > > Change by Roundup Robot <devnull@psf.upfronthosting.co.za>: > > > ---------- > nosy: +python-dev > nosy_count: 5.0 -> 6.0 > pull_requests: +19128 > stage: -> patch review > pull_request: https://github.com/python/cpython/pull/19807 > > _______________________________________ > Python tracker <report@bugs.python.org> > <https://bugs.python.org/issue40358> > _______________________________________ |
|||
| msg370254 - (view) | Author: Domenico Ragusa (d.ragusa) * | Date: 2020-05-28 17:18 | |
I've solved the conflicts with GH-19611 (bpo-23082: Better error message for PurePath.relative_to() from pathlib) that was merged in the mean time and improved the documentation. Everything appears to be in order, can you take a look at it? |
|||
| msg393696 - (view) | Author: Terry J. Reedy (terry.reedy) * ![]() |
Date: 2021-05-14 22:18 | |
On #44078 (closed as duplicate), Mark Hammond made a similar request. |
|||
| msg393777 - (view) | Author: Barney Gale (barneygale) * | Date: 2021-05-17 00:55 | |
Also requested in #42234. |
|||
| msg408249 - (view) | Author: C.A.M. Gerlach (CAM-Gerlach) * | Date: 2021-12-10 21:44 | |
For the record, requested [on Discourse](https://discuss.python.org/t/how-to-go-on-with-a-tiny-improvement-idea-for-pathlib/12472) as well, with a fairly similar proposal. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:59:29 | admin | set | github: 84538 |
| 2022-02-22 23:57:02 | terry.reedy | set | nosy:
- terry.reedy |
| 2022-02-22 23:50:06 | Socob | set | nosy:
+ Socob |
| 2021-12-10 21:44:00 | CAM-Gerlach | set | nosy:
+ CAM-Gerlach messages: + msg408249 |
| 2021-06-23 10:41:51 | serhiy.storchaka | link | issue42234 superseder |
| 2021-06-23 10:41:12 | serhiy.storchaka | link | issue20012 superseder |
| 2021-05-17 00:55:45 | barneygale | set | nosy:
+ barneygale messages: + msg393777 |
| 2021-05-14 22:18:59 | terry.reedy | set | nosy:
+ terry.reedy messages:
+ msg393696 |
| 2021-05-14 22:17:48 | terry.reedy | link | issue44078 superseder |
| 2020-05-28 17:18:23 | d.ragusa | set | messages:
+ msg370254 versions: + Python 3.10, - Python 3.9 |
| 2020-04-30 10:54:35 | CuriousLearner | set | nosy:
+ CuriousLearner |
| 2020-04-30 10:30:01 | d.ragusa | set | pull_requests: + pull_request19133 |
| 2020-04-30 00:49:29 | d.ragusa | set | messages: + msg367723 |
| 2020-04-30 00:03:25 | python-dev | set | nosy:
+ python-dev pull_requests:
+ pull_request19128 |
| 2020-04-29 20:08:41 | ammar2 | set | nosy:
+ ammar2 messages: + msg367697 |
| 2020-04-28 03:53:15 | d.ragusa | set | files: - pathlib.diff |
| 2020-04-28 03:52:45 | d.ragusa | set | files:
+ relative_to.patch messages: + msg367490 |
| 2020-04-22 19:50:21 | eryksun | set | nosy:
+ eryksun messages: + msg367047 |
| 2020-04-22 19:00:13 | d.ragusa | set | messages: + msg367041 |
| 2020-04-22 18:18:16 | pitrou | set | messages: + msg367037 |
| 2020-04-22 05:10:18 | bowiechen | set | nosy:
+ bowiechen |
| 2020-04-22 02:47:14 | xtreak | set | nosy:
+ pitrou |
| 2020-04-22 00:03:03 | d.ragusa | create | |

