-
-
Notifications
You must be signed in to change notification settings - Fork 30.3k
New issue
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
os.path.isabs
change in behavior in Python 3.13 on MS-Windows
#125283
Comments
Works as intended: #113829, maybe a new function could be considered to check if a path is rooted? |
This behavior changes how import os.path
import pathlib
import urllib.parse
>>> urllib.parse.urlparse(pathlib.Path('c:\\xyz').as_uri())
ParseResult(scheme='file', netloc='', path='/c:/xyz', params='', query='', fragment='')
>>> urllib.parse.urlparse(pathlib.Path('\\\\machine\\xyz').as_uri())
ParseResult(scheme='file', netloc='machine', path='/xyz/', params='', query='', fragment='') In Python 3.12, >>> os.path.isabs(urllib.parse.urlparse(pathlib.Path('c:\\xyz').as_uri()).path)
True
>>> os.path.isabs(urllib.parse.urlparse(pathlib.Path('\\\\machine\\xyz').as_uri()).path)
True but not any more in 3.13 >>> os.path.isabs(urllib.parse.urlparse(pathlib.Path('c:\\xyz').as_uri()).path)
False
>>> os.path.isabs(urllib.parse.urlparse(pathlib.Path('\\\\machine\\xyz').as_uri()).path)
False It seems as if |
You can use >>> import pathlib
>>> pathlib.Path.from_uri(pathlib.Path('c:/xyz').as_uri())
WindowsPath('c:/xyz')
>>> pathlib.Path.from_uri(pathlib.Path('//server/drive/xyz').as_uri())
WindowsPath('//server/drive/xyz') This doesn't roundtrip: >>> import pathlib
>>> import urllib.parse
>>> pathlib.Path(urllib.parse.urlparse(pathlib.Path('c:/xyz').as_uri()).path)
WindowsPath('/c:/xyz')
>>> pathlib.Path(urllib.parse.urlparse(pathlib.Path('//server/drive/xyz').as_uri()).path)
WindowsPath('/drive/xyz') Also, aren't uri's always absolute? |
Relative URLs work perfectly fine. EDIT: I meant in general in life, not related to Python. |
Well, at least |
Checking whether it starts with a |
Use >>> import urllib.parse
>>> urllib.parse.urljoin("file://netloc/foo/", "bar")
'file://netloc/foo/bar'
>>> urllib.parse.urljoin("file://netloc/foo/", "/bar")
'file://netloc/bar'
>>> urllib.parse.urljoin("file://netloc/foo/", "//netloc2/bar")
'file://netloc2/bar'
>>> urllib.parse.urljoin("file://netloc/foo/", "file://netloc2/bar")
'file://netloc2/bar' That's also why we changed the behaviour of >>> import os.path
>>> os.path.join(r"c:\foo", "bar")
'c:\\foo\\bar'
>>> os.path.join(r"c:\foo", r"\bar")
'c:\\bar'
>>> os.path.join(r"c:\foo", r"d:\bar")
'd:\\bar' |
I think this can be closed. |
Thanks @nineteendo! Closing. |
Bug report
Bug description:
I'm not sure if this is a fix or a regression issue?
os.path.isabs
use to return True when a windows path started with/
.In python 3.13
In python 3.12
CPython versions tested on:
3.13
Operating systems tested on:
Windows
The text was updated successfully, but these errors were encountered: