Pathlib.path.absolute version confirmation

Could someone just confirm in which version did pathlib.path.absolute got added ? is it python 3.11
cause It is not mentioned in documentation

The method has always been in pathlib, but undocumented. See Issue 29688: Add support for Path.absolute() - Python tracker for some discussions about it. It is now officially tested and documented.


The absolute() method really shouldn’t have been made public until it correctly supported Windows drive-relative paths. For example:

>>> os.chdir('Z:\\Temp')
>>> os.chdir('C:\\')

>>> pathlib.Path('Z:spam').absolute()
>>> os.path.abspath('Z:spam')

Every logical drive (“A:” to “Z:”) has a working directory, which defaults to the root directory. The process also has a current working directory, which can be on either a logical drive or a UNC share. Code that resolves a relative path against only the process working directory is insufficient on Windows. If it’s a relative path that has a drive, such as “Z:spam”, then the working directory on the drive has to be used instead of the process working directory.

1 Like

So can it be said it is not new in version 3.11 right?

It was documented as a public method in 3.11, with new test coverage but without any substantive change to the method’s implementation. You can use it on POSIX in 3.11+, if your code is only ever used on POSIX. I wouldn’t use it in 3.11.0 on Windows since it’s not implemented correctly for drive-relative paths, in which case it returns a relative path. I’d wait for a bugfix release in that case.

1 Like

thanks for that eryk, but i need confirmation because there was an issue raised in cpython GitHub regarding this(issue no: 99387), so i wanted to make pull request by making changes in documentation of python like
'New in version 3.11"

Could you please confirm if it is okay to add that new line in documentation!?

Yes, the absolute() method is newly available in 3.11. The pull request with the new documentation and test coverage wasn’t backported to previous versions, so absolute() is supported only in 3.11 and later.