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

pathlib.PurePath.with_suffix() does not allow removing the suffix #64838

Closed
tifv mannequin opened this issue Feb 16, 2014 · 5 comments
Closed

pathlib.PurePath.with_suffix() does not allow removing the suffix #64838

tifv mannequin opened this issue Feb 16, 2014 · 5 comments
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@tifv
Copy link
Mannequin

tifv mannequin commented Feb 16, 2014

BPO 20639
Nosy @pitrou, @tifv, @serhiy-storchaka
Files
  • pathlib-with_suffix-test.diff: proposed tests
  • pathlib-with_suffix.diff: proposed fix
  • 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 = None
    closed_at = <Date 2014-07-07.01:39:34.620>
    created_at = <Date 2014-02-16.13:28:50.211>
    labels = ['type-bug', 'library']
    title = 'pathlib.PurePath.with_suffix() does not allow removing the suffix'
    updated_at = <Date 2014-07-07.01:39:34.619>
    user = 'https://github.com/tifv'

    bugs.python.org fields:

    activity = <Date 2014-07-07.01:39:34.619>
    actor = 'pitrou'
    assignee = 'none'
    closed = True
    closed_date = <Date 2014-07-07.01:39:34.620>
    closer = 'pitrou'
    components = ['Library (Lib)']
    creation = <Date 2014-02-16.13:28:50.211>
    creator = 'july'
    dependencies = []
    files = ['34099', '34100']
    hgrepos = []
    issue_num = 20639
    keywords = ['patch']
    message_count = 5.0
    messages = ['211316', '211317', '211766', '222428', '222430']
    nosy_count = 4.0
    nosy_names = ['pitrou', 'july', 'python-dev', 'serhiy.storchaka']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue20639'
    versions = ['Python 3.4', 'Python 3.5']

    @tifv
    Copy link
    Mannequin Author

    tifv mannequin commented Feb 16, 2014

    The changeset ef2b2ddd27c8 restricted the argument of Path.with_suffix() too much, and caused some strange behavior.

    Case 1: removing suffix completely is disallowed now.
    The following code worked before the fix:

    >>> pathlib.PurePath('a', 'b.c').with_suffix('')
    PurePosixPath('a/b')

    but now fails with ValueError:

    >>> pathlib.PurePath('a', 'b.c').with_suffix('')
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/home/july/source/python/Lib/pathlib.py", line 760, in with_suffix
        raise ValueError("Invalid suffix %r" % (suffix))
    ValueError: Invalid suffix ''

    It was the only one obvious way of removing the suffix, and I think it should remain so. (BTW: There is a XXX note in the code questioning if Path.with_suffix(None) should remove the suffix.)

    Case 2: while the output is now always a correct Path, the suffix can still contain separator.
    The following code produced incorrect path before the fix:

    >>> pathlib.PurePath('a', 'b.c').with_suffix('./.s/.')
    PurePosixPath('a/b./.s/.')
    >>> _.parts
    ('a', 'b./.s/.')

    Now, the produced path is correct, but the code itself is still allowed:

    >>> pathlib.PurePath('a', 'b.c').with_suffix('./.s/.')
    PurePosixPath('a/b.s')

    while I would expect it to fail with ValueError.

    Attached: proposed test patch.

    @tifv tifv mannequin added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Feb 16, 2014
    @tifv
    Copy link
    Mannequin Author

    tifv mannequin commented Feb 16, 2014

    Proposed patch attached.

    @pitrou
    Copy link
    Member

    pitrou commented Feb 20, 2014

    Thank you! Unfortunately, it is too late for 3.4, but I will make sure the fix is included in 3.4.1 (and 3.5).

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Jul 7, 2014

    New changeset 0d84855861ff by Antoine Pitrou in branch '3.4':
    Issue bpo-20639: calling Path.with_suffix('') allows removing the suffix again.
    http://hg.python.org/cpython/rev/0d84855861ff

    @pitrou
    Copy link
    Member

    pitrou commented Jul 7, 2014

    Sorry for the delay! The patch is now applied. Thank you for contributing!

    @pitrou pitrou closed this as completed Jul 7, 2014
    @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-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant