Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

relpath: Provide better errors when mixing bytes and strings #66082

Closed
bachmann1234 mannequin opened this issue Jun 30, 2014 · 6 comments
Closed

relpath: Provide better errors when mixing bytes and strings #66082

bachmann1234 mannequin opened this issue Jun 30, 2014 · 6 comments
Assignees
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@bachmann1234
Copy link
Mannequin

bachmann1234 mannequin commented Jun 30, 2014

BPO 21883
Nosy @serhiy-storchaka, @Bachmann1234
Files
  • error_message.patch
  • os_path_typeerrors.patch
  • os_path_typeerrors_2.patch
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/serhiy-storchaka'
    closed_at = <Date 2014-10-04.12:12:37.769>
    created_at = <Date 2014-06-30.03:12:55.869>
    labels = ['type-feature', 'library']
    title = 'relpath: Provide better errors when mixing bytes and strings'
    updated_at = <Date 2014-10-04.13:18:52.070>
    user = 'https://github.com/bachmann1234'

    bugs.python.org fields:

    activity = <Date 2014-10-04.13:18:52.070>
    actor = 'python-dev'
    assignee = 'serhiy.storchaka'
    closed = True
    closed_date = <Date 2014-10-04.12:12:37.769>
    closer = 'serhiy.storchaka'
    components = ['Library (Lib)']
    creation = <Date 2014-06-30.03:12:55.869>
    creator = 'Matt.Bachmann'
    dependencies = []
    files = ['35806', '36743', '36744']
    hgrepos = []
    issue_num = 21883
    keywords = ['patch']
    message_count = 6.0
    messages = ['221939', '221940', '227668', '227671', '228449', '228457']
    nosy_count = 3.0
    nosy_names = ['python-dev', 'serhiy.storchaka', 'Matt.Bachmann']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue21883'
    versions = ['Python 3.5']

    @bachmann1234
    Copy link
    Mannequin Author

    bachmann1234 mannequin commented Jun 30, 2014

    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?

    @bachmann1234 bachmann1234 mannequin added stdlib Python modules in the Lib dir type-feature A feature request or enhancement labels Jun 30, 2014
    @bachmann1234
    Copy link
    Mannequin Author

    bachmann1234 mannequin commented Jun 30, 2014

    Includes change and tests.

    The test is similar so I just broke out the logic

    @serhiy-storchaka serhiy-storchaka self-assigned this Sep 27, 2014
    @serhiy-storchaka
    Copy link
    Member

    Error message for posixpath.join() was fixed and enhanced in bpo-22034. Here is a patch which extends this enhancement to relpath() and to other os.path implementations (ntpath and macpath).

    @serhiy-storchaka
    Copy link
    Member

    Ah, tests fail when Python runs without the -bb option. Here is fixed path.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Oct 4, 2014

    New changeset 2ba2ee5713bd by Serhiy Storchaka in branch 'default':
    Issue bpo-21883: os.path.join() and os.path.relpath() now raise a TypeError with
    https://hg.python.org/cpython/rev/2ba2ee5713bd

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Oct 4, 2014

    New changeset 85de13b746ac by Serhiy Storchaka in branch 'default':
    Fixed tests on Windows for issue bpo-21883.
    https://hg.python.org/cpython/rev/85de13b746ac

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant