8000 gh-112578: Fix RuntimeWarning when running zipfile by hauntsaninja · Pull Request #112579 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-112578: Fix RuntimeWarning when running zipfile #112579

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

Merged
merged 3 commits into from
Dec 3, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
gh-112578: Fix RuntimeWarning when running zipfile
  • Loading branch information
hauntsaninja committed Dec 1, 2023
commit 13d46719fe51d6e34b6c32184ccf29df48a6b8a5
9 changes: 5 additions & 4 deletions Lib/test/test_zipfile/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import unittest
import unittest.mock as mock
import zipfile
import zipfile.__main__ as zipfile_main


from tempfile import TemporaryFile
Expand Down Expand Up @@ -3184,16 +3185,16 @@ def test_cli_with_metadata_encoding(self):
args = ["--metadata-encoding=shift_jis", "-c", "nonesuch", "nonesuch"]
with captured_stdout() as stdout:
with captured_stderr() as stderr:
self.assertRaises(SystemExit, zipfile.main, args)
self.assertRaises(SystemExit, zipfile_main.main, args)
self.assertEqual(stdout.getvalue(), "")
self.assertIn(errmsg, stderr.getvalue())

with captured_stdout() as stdout:
zipfile.main(["--metadata-encoding=shift_jis", "-t", TESTFN])
zipfile_main.main(["--metadata-encoding=shift_jis", "-t", TESTFN])
listing = stdout.getvalue()

with captured_stdout() as stdout:
zipfile.main(["--metadata-encoding=shift_jis", "-l", TESTFN])
zipfile_main.main(["--metadata-encoding=shift_jis", "-l", TESTFN])
listing = stdout.getvalue()
for name in self.file_names:
self.assertIn(name, listing)
Expand All @@ -3211,7 +3212,7 @@ def test_cli_with_metadata_encoding_extract(self):
except UnicodeEncodeError:
self.skipTest(f'cannot encode file name {fn!r}')

zipfile.main(["--metadata-encoding=shift_jis", "-e", TESTFN, TESTFN2])
zipfile_main.main(["--metadata-encoding=shift_jis", "-e", TESTFN, TESTFN2])
listing = os.listdir(TESTFN2)
for name in self.file_names:
self.assertIn(name, listing)
Expand Down
3 changes: 0 additions & 3 deletions Lib/zipfile/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2233,6 +2233,3 @@ def _compile(file, optimize=-1):
# used privately for tests
CompleteDirs, # noqa: F401
)

# used privately for tests
from .__main__ import main # noqa: F401, E402
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe simply remove this import?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what I did initially (see first commit). But I want to backport this change and I got worried because zipfile.main has existed for 15 years and that comment has only existed for one year.

I found one use in the wild too: https://github.com/ThoreBor/Anki_Leaderboard/blob/master/tools/ankiaddon.py

0