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

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

Closed
treyhunner opened this issue Jul 14, 2022 · 7 comments
Closed
Assignees
Labels
3.10 only security fixes 3.11 only security fixes 3.12 bugs and security fixes topic-pathlib type-bug An unexpected behavior, bug, or error

Comments

@treyhunner
Copy link
Member

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
@treyhunner treyhunner added the type-bug An unexpected behavior, bug, or error label Jul 14, 2022
@kumaraditya303 kumaraditya303 added 3.11 only security fixes 3.12 bugs and security fixes topic-pathlib labels Jul 14, 2022
@tiran
Copy link
Member

tiran commented Jul 14, 2022

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

@serhiy-storchaka serhiy-storchaka added the 3.10 only security fixes label Jul 14, 2022
@serhiy-storchaka
Copy link
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.

serhiy-storchaka pushed a commit that referenced this issue Jul 20, 2022
Co-authored-by: Barney Gale <barney.gale@gmail.com>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Jul 20, 2022
…honGH-94846)

Co-authored-by: Barney Gale <barney.gale@gmail.com>
(cherry picked from commit ed44415)

Co-authored-by: Oleg Iarygin <oleg@arhadthedev.net>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Jul 20, 2022
…honGH-94846)

Co-authored-by: Barney Gale <barney.gale@gmail.com>
(cherry picked from commit ed44415)

Co-authored-by: Oleg Iarygin <oleg@arhadthedev.net>
miss-islington added a commit that referenced this issue Jul 20, 2022
Co-authored-by: Barney Gale <barney.gale@gmail.com>
(cherry picked from commit ed44415)

Co-authored-by: Oleg Iarygin <oleg@arhadthedev.net>
miss-islington added a commit that referenced this issue Jul 20, 2022
Co-authored-by: Barney Gale <barney.gale@gmail.com>
(cherry picked from commit ed44415)

Co-authored-by: Oleg Iarygin <oleg@arhadthedev.net>
@gvanrossum
Copy link
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?)

@merwok
Copy link
Member

merwok commented Oct 4, 2022

Don’t see any revert in file history: https://github.com/python/cpython/commits/3.11/Lib/shutil.py

@gvanrossum
Copy link
Member

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

It looks like this was fixed by GH-94846.

@serhiy-storchaka
Copy link
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.

@gvanrossum
Copy link
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
Labels
3.10 only security fixes 3.11 only security fixes 3.12 bugs and security fixes topic-pathlib type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

6 participants