[New-bugs-announce] [issue22587] os.path.abspath(None) behavior is inconsistent between platforms

Kevin Keating report at bugs.python.org
Thu Oct 9 18:56:13 CEST 2014


New submission from Kevin Keating:

On Windows, os.path.abspath() treats None as if it were an empty string, so os.path.abspath(None) returns the current working directory.  On Linux, os.path.abspath(None) raises an AttributeError.  With macpath, abspath(None) raises a TypeError.  I've seen this behavior with Python 2.7.3, 2.7.8, 3.2.5, and 3.4.2.

Python 3.4.2 (v3.4.2:ab2c023a9432, Oct  6 2014, 22:15:05) [MSC v.1600 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import ntpath, posixpath, macpath
>>> ntpath.abspath(None)
'C:\\Users\\Keating\\Documents'
>>> posixpath.abspath(None)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\programs\Python34\lib\posixpath.py", line 357, in abspath
    if not isabs(path):
  File "C:\programs\Python34\lib\posixpath.py", line 63, in isabs
    return s.startswith(sep)
AttributeError: 'NoneType' object has no attribute 'startswith'
>>> macpath.abspath(None)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\programs\Python34\lib\macpath.py", line 177, in abspath
    if not isabs(path):
  File "C:\programs\Python34\lib\macpath.py", line 49, in isabs
    return colon in s and s[:1] != colon
TypeError: argument of type 'NoneType' is not iterable

This case seems very closely related to http://bugs.python.org/issue9018, which noted a platform inconsistency in os.path.normcase.

----------
components: Library (Lib)
messages: 228883
nosy: KevKeating
priority: normal
severity: normal
status: open
title: os.path.abspath(None) behavior is inconsistent between platforms
versions: Python 2.7, Python 3.2, Python 3.4

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue22587>
_______________________________________


More information about the New-bugs-announce mailing list