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.

classification
Title: os.path.join() converts None to '' by default
Type: enhancement Stage:
Components: Library (Lib) Versions: Python 3.4
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: eric.araujo, eric.smith, georg.brandl, hallaj, r.david.murray
Priority: normal Keywords:

Created on 2013-03-27 07:05 by hallaj, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (5)
msg185316 - (view) Author: Muhammad Hallaj Subery (hallaj) Date: 2013-03-27 07:05
I think the default behavior of os.path.join() when None is passed as the first argument should be to translate it to '' by default.

>>> import os
>>> os.path.join(None, 'somewhere')
'somewhere'

vs the current

>>> import os
>>> os.path.join(None, 'somewhere')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/posixpath.py", line 68, in join
    elif path == '' or path.endswith('/'):
AttributeError: 'NoneType' object has no attribute 'endswith'
msg185317 - (view) Author: Muhammad Hallaj Subery (hallaj) Date: 2013-03-27 07:07
I believe this can be easily archived by adding the following changes:

64c64
<     path = a or ''
---
>
msg185364 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2013-03-27 18:47
I think it is probably better to keep the error, myself.  It seems to me that a None creeping in is more likely to be an error in the program.   But I could be convinced otherwise :)

What is your use case?
msg185367 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2013-03-27 19:03
I agree with David. This is a programming error, and should result in an exception.
msg185409 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2013-03-28 09:53
Since most other os.path functions also choke (intentionally) on None values, I agree and would point out that if you want this behavior, it's easy to do the "or ''" dance on the caller side.
History
Date User Action Args
2022-04-11 14:57:43adminsetgithub: 61756
2013-03-28 09:53:36georg.brandlsetstatus: open -> closed

nosy: + georg.brandl
messages: + msg185409

resolution: rejected
2013-03-28 04:00:50eric.araujosetnosy: + eric.araujo
2013-03-27 19:03:20eric.smithsetnosy: + eric.smith
messages: + msg185367
2013-03-27 18:47:06r.david.murraysetnosy: + r.david.murray

messages: + msg185364
versions: - Python 2.6, Python 3.1, Python 2.7, Python 3.2, Python 3.3, Python 3.5
2013-03-27 07:07:09hallajsetmessages: + msg185317
2013-03-27 07:05:17hallajcreate