Skip to content

Add suffix property to zipfile.Path #88261

Description

@MrQubo
mannequin
BPO 44095
Nosy @jaraco, @miguendes, @MrQubo
PRs
  • bpo-44095: Add suffix, stem and suffixes to zipfile.Path #26129
  • 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 2021-05-14.18:00:17.721>
    created_at = <Date 2021-05-10.05:29:23.213>
    labels = ['type-feature', 'library', '3.11']
    title = 'Add suffix property to zipfile.Path'
    updated_at = <Date 2021-05-14.18:00:17.720>
    user = 'https://github.com/MrQubo'

    bugs.python.org fields:

    activity = <Date 2021-05-14.18:00:17.720>
    actor = 'jaraco'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-05-14.18:00:17.721>
    closer = 'jaraco'
    components = ['Library (Lib)']
    creation = <Date 2021-05-10.05:29:23.213>
    creator = 'MrQubo'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 44095
    keywords = ['patch']
    message_count = 6.0
    messages = ['393352', '393637', '393650', '393671', '393682', '393683']
    nosy_count = 3.0
    nosy_names = ['jaraco', 'miguendes', 'MrQubo']
    pr_nums = ['26129']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue44095'
    versions = ['Python 3.11']

    Activity

    1. MrQubo commented on May 10, 2021

      MrQubomannequin
      MannequinAuthor

      suffix property is present on pathlib.Path (specifically pathlib.PurePath) and it could also be added to zipfile.Path for consistency.

      My use case is filtering files by suffix:
      patch_files = list(filter(lambda file: file.suffix == '.patch', files))

      Besides suffix also most of the other pathlib.PurePath properties and methods could be added.

    2. added
      stdlibStandard Library Python modules in the Lib/ directory
      type-featureA feature request or enhancement
      on May 10, 2021
    3. miguendes commented on May 14, 2021

      miguendesmannequin
      Mannequin

      +1.

      The docstring says:

      class Path:
          """
          A pathlib-compatible interface for zip files.
      

      but only a few methods are supported. It'd be nice to have at least stem, parents, suffixes, parts, which IMHO would make sense here.

      I'd love to work on this if the Core Devs think it makes sense and if OP is not doing so also.

    4. MrQubo commented on May 14, 2021

      MrQubomannequin
      MannequinAuthor

      Thank for your interest Miguel. I have no experience with CPython codebase so I'll be glad if you work on this.

      I think treating ZipFile's like a separate drive would be the best. If we agree on this then probably all of the properties and methods from pathlib could be implemented. But without this at least suffix, suffixes, stem, with_name(), with_stem(), and with_suffix() makes perfect sense.

      If some of the properties/methods won't be implemented on zipfile.Path then it would be useful to raise NotImplementedError. Currently, trying to use suffix property, raises the error AttributeError: 'Path' object has no attribute 'suffix'. This is confusing as the name of the class is the same as in pathlib.Path so it's not immediately obvious that it meant zipfile.Path.

      The use-case for mimicking those two interfaces closely is to use both interchangeably (thanks to duck-typing).

    5. miguendes commented on May 14, 2021

      miguendesmannequin
      Mannequin

      I prototyped something by adding suffix, suffixes, and stem. To me these are the most obvious ones and would be useful right away.

      Regarding the others I'm not so sure. It seems that zipfile.Path is just a convenient class to provide basic navigational operations. It's not meant to be 100% consistent with pathlib.Path.

      In any case, it'd nice to discuss it.

      Here it is: #26129

    6. jaraco commented on May 14, 2021

      @jaraco
      Member

      Sounds good to me. In general, it's easier to contribute first to https://github.com/jaraco/zipp and those changes can be readily merged into CPython. No worries, though. If these changes can be accepted here, I should be able to graft them onto jaraco/zipp as well, and thus provide the functionality for older Pythons.

      At this point, Python 3.10 is frozen for features, which this change would be, so I'm updating the target version to 3.11.

      It's not meant to be 100% consistent with pathlib.Path.

      That's right. It's meant to provide whatever consistency makes sense, but a subset of what's available on pathlib.Path. Happy to accept any contributions that would be useful.

      > A pathlib-compatible interface
      only a few methods are supported

      Indeed, perhaps the documentation should be more clear about what is and isn't supported.

    7. added
      3.11only security fixes
      and removed on May 14, 2021
    8. jaraco commented on May 14, 2021

      @jaraco
      Member

      Thanks for the excellent patch. I've created jaraco/zipp#74 to track the backport of these changes.

    9. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      3.11only security fixesstdlibStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancement

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions