You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
os.path.isabs change in behavior in Python 3.13 on MS-Windows #125283
Works as intended: #113829, maybe a new function could be considered to check if a path is rooted?
This behavior changes how os.path.isabs interacts with urllib.parse.urlparse when dealing with absolute paths in Windows URIs. In Python 3.12, paths parsed from local file URIs (drive and network paths) were recognized as absolute, but in Python 3.13, they no longer are
It seems as if os.path.isabs was never intended to be used with ParseResult paths. I suppose a more appropriate solution would be to directly check if the path starts with '/', which would indicate that it's absolute.
It seems as if os.path.isabs was never intended to be used with ParseResult paths. I suppose a more appropriate solution would be to directly check if the path starts with '/', which would indicate that it's absolute.
Checking whether it starts with a / makes most sense to me. Another option is posixpath.isabs().
the doc updated in #113829 still indicates the following behavior:
Return ``True`` if *path* is an absolute pathname. On Unix, that means it
begins with a slash, on Windows that it begins with two (back)slashes, or a
drive letter, colon, and (back)slash together.
whereas the intended behavior, as illustrated in Lib/test/test_ntpath.py, appears to be now :
>>> os.path.isabs("/foo/bar") # path beginning with a slash on windows
False
>>> os.path.isabs("\\foo\\bar") # path beginning with two backslashes on windows
False
Hey @kayychou - "\\foo\\bar" expresses a string that begins with a single backslash. If you want two backslashes, you could use a raw string (r"\\foo\bar") or double the backslashes ("\\\\foo\\bar")
Activity
nineteendo commentedon Oct 11, 2024
Works as intended: #113829, maybe a new function could be considered to check if a path is rooted?
ikappaki commentedon Oct 11, 2024
This behavior changes how
os.path.isabsinteracts withurllib.parse.urlparsewhen dealing with absolute paths in Windows URIs. In Python 3.12, paths parsed from local file URIs (drive and network paths) were recognized as absolute, but in Python 3.13, they no longer areIn Python 3.12,
os.path.isabswould correctly identify these paths as absolute, including network paths:but not any more in 3.13
It seems as if
os.path.isabswas never intended to be used with ParseResultpaths. I suppose a more appropriate solution would be to directly check if thepathstarts with '/', which would indicate that it's absolute.nineteendo commentedon Oct 11, 2024
You can use
pathlib.Path.from_uri()starting from 3.13:This doesn't roundtrip:
Also, aren't uri's always absolute?
marc-hb commentedon Oct 11, 2024
Relative URLs work perfectly fine.
EDIT: I meant in general in life, not related to Python.
nineteendo commentedon Oct 11, 2024
Well, at least
pathlibdoesn't allow creating them.barneygale commentedon Oct 11, 2024
Checking whether it starts with a
/makes most sense to me. Another option isposixpath.isabs().nineteendo commentedon Oct 11, 2024
Use
p.scheme and p.netloc and p.path.startswith("/")to check if an uri is absolute, an absolute path doesn't change when joined with another path:That's also why we changed the behaviour of
os.path.isabs():nineteendo commentedon Oct 11, 2024
I think this can be closed.
barneygale commentedon Oct 11, 2024
Thanks @nineteendo! Closing.
kayychou commentedon Dec 3, 2024
hi @nineteendo, @barneygale,
the doc updated in #113829 still indicates the following behavior:
whereas the intended behavior, as illustrated in Lib/test/test_ntpath.py, appears to be now :
maybe I'm missing something under the hood
Thanks for your help!
barneygale commentedon Dec 3, 2024
Hey @kayychou -
"\\foo\\bar"expresses a string that begins with a single backslash. If you want two backslashes, you could use a raw string (r"\\foo\bar") or double the backslashes ("\\\\foo\\bar")For more info: https://docs.python.org/3/reference/lexical_analysis.html#escape-sequences