Skip to content

tarfile does not support pathlib #72417

Closed

Description

@ethanfurman
BPO 28230
Nosy @brettcannon, @gustaebel, @ned-deily, @ethanfurman, @berkerpeksag, @serhiy-storchaka
PRs
  • bpo-28230: Document the pathlib support in tarfile and add tests. #512
  • [3.6] bpo-28230: Document the pathlib support in tarfile and add tests. #559
  • Files
  • open-tarfile.stoneleaf.patch
  • issue28230_v2.diff
  • test_tarfile_pathlike.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 = None
    closed_at = <Date 2017-03-15.12:52:09.446>
    created_at = <Date 2016-09-21.07:31:34.259>
    labels = ['3.7', 'type-bug', 'library']
    title = 'tarfile does not support pathlib'
    updated_at = <Date 2017-03-24.22:41:49.995>
    user = 'https://github.com/ethanfurman'

    bugs.python.org fields:

    activity = <Date 2017-03-24.22:41:49.995>
    actor = 'serhiy.storchaka'
    assignee = 'none'
    closed = True
    closed_date = <Date 2017-03-15.12:52:09.446>
    closer = 'berker.peksag'
    components = ['Library (Lib)']
    creation = <Date 2016-09-21.07:31:34.259>
    creator = 'ethan.furman'
    dependencies = []
    files = ['44772', '45042', '45051']
    hgrepos = []
    issue_num = 28230
    keywords = ['patch']
    message_count = 9.0
    messages = ['278414', '278416', '278428', '278444', '288604', '289096', '289671', '290265', '290267']
    nosy_count = 6.0
    nosy_names = ['brett.cannon', 'lars.gustaebel', 'ned.deily', 'ethan.furman', 'berker.peksag', 'serhiy.storchaka']
    pr_nums = ['512', '559']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue28230'
    versions = ['Python 3.6', 'Python 3.7']

    Activity

    1. added
      type-bug
      on Sep 21, 2016
    2. added
      stdlib
      on Oct 5, 2016
    3. berkerpeksag commented on Oct 10, 2016

      @berkerpeksag
      Member

      Here's an updated patch with different tests and documentation changes. I simplified Lib/tarfile.py a bit (see my review comments)

      A slightly off-topic question: I had to update both docstrings and documentation. Should we use this as an opportunity to simplify the docstrings?

    4. serhiy-storchaka commented on Oct 10, 2016

      @serhiy-storchaka
      Member

      There are two kinds of paths in tarinfo:

      1. External paths that correspond to filesystem paths. The path of the tar file itself, patches of added files and target directory for extraction. Supporting path protocol looks reasonable for them.

      2. Internal paths, they are just string keys inside an archive. They come from TarFile.getnames() and always are strings. I'm not sure that pathlib have relation to this. This issue needs more thoughts. I would not haste with this.

    5. ethanfurman commented on Oct 10, 2016

      @ethanfurman
      MemberAuthor

      As Serhiy was alluding to, if the incoming path is for the actual tar file and is only passed along to Python itself then we probably don't need to worry about os.fspath(). For names that will be interally stored, or are for accessing internal files, then the proper sequence is check for and call os.fspath if necessary, and then double-check that the name to be used is a str. The double-check is needed because os.fspath may return a bytes object, which tar does not allow.

    6. serhiy-storchaka commented on Oct 10, 2016

      @serhiy-storchaka
      Member

      It seems to me that tarfile already supports path protocol for all external patches and no changes for tarfile are needed.

      Proposed patch adds tests for (already implemented) support of pathlike protocol in tarfile.

    7. berkerpeksag commented on Feb 26, 2017

      @berkerpeksag
      Member

      Serhiy's patch looks good to me, but it would be nice to document the support for PathLike objects in the tarfile documentation.

    8. serhiy-storchaka commented on Mar 6, 2017

      @serhiy-storchaka
      Member

      Updated documentation.

      Note that path-like objects are supported only for external names. Internal names are not OS paths.

    9. berkerpeksag commented on Mar 15, 2017

      @berkerpeksag
      Member

      PR 512 has been merged and backported to 3.6 branch. I think this can be closed now. Thanks, Ethan and Serhiy!

    10. serhiy-storchaka commented on Mar 24, 2017

      @serhiy-storchaka
      Member

      New changeset 666165f by Serhiy Storchaka in branch '3.6':
      [3.6] bpo-28230: Document the pathlib support in tarfile and add tests. (#559)
      666165f

    11. serhiy-storchaka commented on Mar 24, 2017

      @serhiy-storchaka
      Member

      New changeset c45cd16 by Serhiy Storchaka in branch 'master':
      bpo-28230: Document the pathlib support in tarfile and add tests. (#512)
      c45cd16

    12. 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.7 (EOL)stdlibtype-bug

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions