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

Implement Preset Argument in tarfile.open Function and Add Test Coverage #11251

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

karimbaidar
Copy link

This pull request addresses the and Closes #11072 issue. The preset argument was missing from the tarfile.open function in the tarfile.pyi stub file. This argument is used to set the compression level when opening a tarfile in write mode with the xz method.

Changes made:

  • Added preset: int | None = ... to the open function in tarfile.pyi.
  • To verify these changes, a test script was written and placed in the tests directory. This script uses the tarfile.open function with the preset argument in various ways to cover different edge cases.

How to Run the Test:

  • The test script can be run directly with the Python interpreter:
    mypy --custom-typeshed-dir=<path_to_the_typeshed_dir> tests/test_tarfile.py

This will execute the script and print the output to the console.

How the Test Works:
The test script checks the following scenarios:

  • Valid preset values: The script opens a tarfile in write mode with the xz method and a preset value ranging from 0 to 9. No errors should be raised in this case.
  • Invalid preset values: The script attempts to open a tarfile with preset values of -1, 10, “high”, and 5.5. These values are invalid because preset should be an integer between 0 and 9 inclusive. The script checks that a ValueError or TypeError is raised in these cases.
  • Modes that don’t support preset: The script attempts to open a tarfile in read mode and write mode (without the xz method) with a preset value. These modes do not support the preset argument, so the script checks that a tarfile.TarError is raised.

By covering these scenarios, the test script ensures that the preset argument is correctly recognized and handled by the tarfile.open function.

This comment has been minimized.

Copy link
Contributor

github-actions bot commented Jan 5, 2024

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

tarfile.open() is missing preset kwarg
1 participant