Skip to content

shutil.make_archive now fails with pathlib.Path object in Python 3.11.0b4 #94844

Description

@treyhunner

Bug report

This code works on Python 3.10 and Python 3.11.0a5 but raises a TypeError in Python 3.11.0b4:

from pathlib import Path
from shutil import make_archive
path = Path.cwd().resolve()
make_archive(path, 'zip', path.parent, path.name)

Here's the output I see in Python 3.11.0b4:

>>> from pathlib import Path
>>> from shutil import make_archive
>>> path = Path.cwd().resolve()
>>> make_archive(path, 'zip', path.parent, path.name)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/trey/.pyenv/versions/3.11.0b4/lib/python3.11/shutil.py", line 1130, in make_archive
    filename = func(base_name, base_dir, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/trey/.pyenv/versions/3.11.0b4/lib/python3.11/shutil.py", line 977, in _make_zipfile
    zip_filename = base_name + ".zip"
                   ~~~~~~~~~~^~~~~~~~
TypeError: unsupported operand type(s) for +: 'PosixPath' and 'str'

Your environment

  • CPython versions tested on: Python 3.11.0b4
  • Operating system and architecture: 64-bit Ubuntu Linux 20.04

Activity

  1. tiran commented on Jul 14, 2022

    @tiran
    Member

    It is most likely related to gh-74696 / GH-93160 .

  2. serhiy-storchaka commented on Jul 14, 2022

    @serhiy-storchaka
    Member

    It was not documented, and it only worked if root_dir is not None. It was not supported feature, it was a side effect of calling abspath() for base_name. Unsurprisingly, there were no tests for this.

    So we now have several options:

    • Do nothing. No supported feature was broken -- nothing to fix.
    • Add that feature officially (with tests and documentation) in bugfix releases.
    • Only fix what was broken (accept Path-like objects if root_dir is not None), but do not document it. Added tests should contain a comment that it is an implementation detail. In 3.12 we can also either remove this partial feature, or implement it completely and support officially.
  3. added a commit that references this issue on Jul 20, 2022
  4. added 4 commits that reference this issue on Jul 20, 2022
  5. gvanrossum commented on Oct 4, 2022

    @gvanrossum
    Member

    IIUC this was reverted and we're trying again for 3.12. See #94251 (PR) and #74696 (issue).

    Shall we close this as fixed? (I don't actually see the commits that reverted this -- how to find those?)

  6. merwok commented on Oct 4, 2022

    @merwok
    Member
  7. gvanrossum commented on Oct 4, 2022

    @gvanrossum
    Member

    Yeah, I think I misunderstood (or confused this with another, unrelated issue).

    It looks like this was fixed by GH-94846.

  8. serhiy-storchaka commented on Oct 5, 2022

    @serhiy-storchaka
    Member

    #94846 only restored the old behavior which was an implementation artifact -- undocumented and not consistent. Path-like object as base_name is only accepted if root_dir is not None.

    If we want to make it an official feature, we should document it, cover by tests, and make it working for root_dir=None. Otherwise we can broke it and revert #94846 for 3.12.

  9. gvanrossum commented on Oct 5, 2022

    @gvanrossum
    Member

    Then let's do the latter -- make it work for more cases, document it (lightly), and test it (briefly). And it's worth a new issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

3.10 (EOL)end of life3.11only security fixes3.12only security fixestopic-pathlibtype-bugAn unexpected behavior, bug, or error

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions