This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2013年12月07日 11:02 by serhiy.storchaka, last changed 2022年04月11日 14:57 by admin. This issue is now closed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| pathlib_relative_to.patch | serhiy.storchaka, 2013年12月07日 11:47 | review | ||
| pathlib_relative_to_2.patch | serhiy.storchaka, 2013年12月07日 13:02 | review | ||
| Messages (7) | |||
|---|---|---|---|
| msg205448 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) | Date: 2013年12月07日 11:02 | |
>>> import pathlib
>>> pathlib.PureWindowsPath('C:/Foo/Bar').relative_to('C:/Foo')
PureWindowsPath('Bar')
>>> pathlib.PureWindowsPath('C:/Foo/Bar').relative_to('C:/foo')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/serhiy/py/cpython/Lib/pathlib.py", line 797, in relative_to
.format(str(self), str(formatted)))
ValueError: 'C:\\Foo\\Bar' does not start with 'C:\\foo'
>>> pathlib.PureWindowsPath('C:/Foo/Bar').relative_to('c:/Foo')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/serhiy/py/cpython/Lib/pathlib.py", line 797, in relative_to
.format(str(self), str(formatted)))
ValueError: 'C:\\Foo\\Bar' does not start with 'c:\\Foo'
It also returns strange result when an argument is naked drive:
>>> pathlib.PureWindowsPath('C:/Foo/Bar').relative_to('C:')
PureWindowsPath('//Foo/Bar')
|
|||
| msg205450 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) | Date: 2013年12月07日 11:47 | |
Here is a patch which fixes first bug. |
|||
| msg205452 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) | Date: 2013年12月07日 13:02 | |
Actually relative_to() returns invalid path object.
>>> import pathlib
>>> p = pathlib.PureWindowsPath('C:/Foo/Bar/Baz').relative_to('C:')
>>> p
PureWindowsPath('//Foo/Bar/Baz')
>>> str(p)
'\\\\Foo\\Bar\\Baz'
>>> p.drive
''
>>> p.root
''
>>> p.parts
('\\', 'Foo', 'Bar', 'Baz')
>>> p.is_absolute()
False
>>> p2 = pathlib.PureWindowsPath(str(p))
>>> p2.drive
'\\\\Foo\\Bar'
>>> p2.root
'\\'
>>> p2.parts
('\\\\Foo\\Bar\\', 'Baz')
>>> p2.is_absolute()
True
Here is a patch which fixes both bugs.
>>> import pathlib
>>> p = pathlib.PureWindowsPath('C:/Foo/Bar/Baz').relative_to('C:')
>>> p
PureWindowsPath('/Foo/Bar/Baz')
>>> str(p)
'\\Foo\\Bar\\Baz'
>>> p.drive
''
>>> p.root
'\\'
>>> p.parts
('\\', 'Foo', 'Bar', 'Baz')
|
|||
| msg207042 - (view) | Author: Roundup Robot (python-dev) (Python triager) | Date: 2013年12月28日 18:49 | |
New changeset 763f4416c4fd by Antoine Pitrou in branch 'default': Issue #19918: Fix PurePath.relative_to() under Windows. http://hg.python.org/cpython/rev/763f4416c4fd |
|||
| msg207043 - (view) | Author: Antoine Pitrou (pitrou) * (Python committer) | Date: 2013年12月28日 18:49 | |
Thanks! I've tweaked the patch a bit and committed it. |
|||
| msg232878 - (view) | Author: Chris Jerdonek (chris.jerdonek) * (Python committer) | Date: 2014年12月18日 13:55 | |
Was this also fixed for Mac OS X? Mac OS X is also case-insensitive by default, and on Python 3.4.2 I'm getting:
>>> Path("Foo").relative_to("foo")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/pathlib.py", line 806, in relative_to
.format(str(self), str(formatted)))
ValueError: 'Foo' does not start with 'foo'
|
|||
| msg232882 - (view) | Author: Antoine Pitrou (pitrou) * (Python committer) | Date: 2014年12月18日 15:00 | |
pathlib is case-sensitive under OS X (under any non-Windows platform actually). |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:57:55 | admin | set | github: 64117 |
| 2015年07月16日 21:29:29 | Aaron Meurer | set | nosy:
+ Aaron Meurer |
| 2014年12月18日 15:00:05 | pitrou | set | messages: + msg232882 |
| 2014年12月18日 13:55:37 | chris.jerdonek | set | nosy:
+ chris.jerdonek messages: + msg232878 |
| 2013年12月28日 18:49:45 | pitrou | set | status: open -> closed resolution: fixed messages: + msg207043 stage: patch review -> resolved |
| 2013年12月28日 18:49:10 | python-dev | set | nosy:
+ python-dev messages: + msg207042 |
| 2013年12月11日 22:31:28 | serhiy.storchaka | set | assignee: pitrou |
| 2013年12月07日 13:02:46 | serhiy.storchaka | set | files:
+ pathlib_relative_to_2.patch messages: + msg205452 |
| 2013年12月07日 11:47:19 | serhiy.storchaka | set | files:
+ pathlib_relative_to.patch keywords: + patch messages: + msg205450 stage: needs patch -> patch review |
| 2013年12月07日 11:02:31 | serhiy.storchaka | create | |