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: relpath: Provide better errors when mixing bytes and strings
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: serhiy.storchaka Nosy List: Matt.Bachmann, python-dev, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2014-06-30 03:12 by Matt.Bachmann, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
error_message.patch Matt.Bachmann, 2014-06-30 03:25 review
os_path_typeerrors.patch serhiy.storchaka, 2014-09-27 12:41 review
os_path_typeerrors_2.patch serhiy.storchaka, 2014-09-27 13:21 review
Messages (6)
msg221939 - (view) Author: Matt Bachmann (Matt.Bachmann) * Date: 2014-06-30 03:12
Howdy!

I encountered this error when accidently passing in mixed types to reldir

>>> import os
>>> os.path.relpath('/Users/bachmann', b'.')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/Cellar/python3/3.4.1/Frameworks/Python.framework/Versions/3.4/lib/python3.4/posixpath.py", line 451, in relpath
    start_list = [x for x in abspath(start).split(sep) if x]
TypeError: Type str doesn't support the buffer API

When this mistake is done in join we get a helpful error message.

I simply borrowed this logic and put in in relpath. Is this useful?
msg221940 - (view) Author: Matt Bachmann (Matt.Bachmann) * Date: 2014-06-30 03:25
Includes change and tests.

The test is similar so I just broke out the logic
msg227668 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-09-27 12:41
Error message for posixpath.join() was fixed and enhanced in issue22034. Here is a patch which extends this enhancement to relpath() and to other os.path implementations (ntpath and macpath).
msg227671 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-09-27 13:21
Ah, tests fail when Python runs without the -bb option.  Here is fixed path.
msg228449 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2014-10-04 12:10
New changeset 2ba2ee5713bd by Serhiy Storchaka in branch 'default':
Issue #21883: os.path.join() and os.path.relpath() now raise a TypeError with
https://hg.python.org/cpython/rev/2ba2ee5713bd
msg228457 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2014-10-04 13:18
New changeset 85de13b746ac by Serhiy Storchaka in branch 'default':
Fixed tests on Windows for issue #21883.
https://hg.python.org/cpython/rev/85de13b746ac
History
Date User Action Args
2022-04-11 14:58:05adminsetgithub: 66082
2014-10-04 13:18:52python-devsetmessages: + msg228457
2014-10-04 12:12:37serhiy.storchakasetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2014-10-04 12:10:37python-devsetnosy: + python-dev
messages: + msg228449
2014-09-27 13:21:51serhiy.storchakasetfiles: + os_path_typeerrors_2.patch

messages: + msg227671
2014-09-27 12:41:38serhiy.storchakasetfiles: + os_path_typeerrors.patch

messages: + msg227668
2014-09-27 10:57:21serhiy.storchakasetassignee: serhiy.storchaka
stage: patch review

nosy: + serhiy.storchaka
versions: + Python 3.5, - Python 3.4
2014-06-30 03:25:44Matt.Bachmannsetfiles: + error_message.patch

messages: + msg221940
2014-06-30 03:25:15Matt.Bachmannsetfiles: - error_message.patch
2014-06-30 03:13:30Matt.Bachmannsetfiles: + error_message.patch
keywords: + patch
2014-06-30 03:12:55Matt.Bachmanncreate