Skip to content

Fix deprecated UTC and tar extraction calls #75 - #111

Open
shashank-tomar0 wants to merge 1 commit into
aboutcode-org:mainfrom
shashank-tomar0:fix/deprecation-warnings
Open

shashank-tomar0 wants to merge 1 commit into
aboutcode-org:mainfrom
shashank-tomar0:fix/deprecation-warnings

Conversation

@shashank-tomar0

@shashank-tomar0 shashank-tomar0 commented Nov 8, 2026 •

Copy link
Copy Markdown

Summary

Fixes #75.

This removes both DeprecationWarnings reported in the issue.

Changes

  • src/commoncode/timeutils.py: time2tstamp() now uses
    datetime.now(timezone.utc).replace(tzinfo=None). Dropping tzinfo keeps
    the historical naive-UTC return value and the timestamp format unchanged.
  • src/commoncode/archive.py: added a small _extractall() helper that always
    passes an explicit filter to TarFile.extractall() when the running Python
    supports it, with a TypeError fallback for older versions.
    • The default is fully_trusted, which preserves the historical extraction
      behavior when Python 3.14 changes the default filter to data.
    • The explicit filter argument of extract_tar() is now honored on every
      Python that supports it. Previously it was only passed on Python 3.14.
    • On Pythons without the filter argument (CI also runs 3.10) the argument
      is still ignored as before instead of raising a TypeError.

Tests

$ python -m pytest tests/test_timeutils.py tests/test_archive.py -q
20 passed

New coverage:

  • test_time2tstamp_does_not_emit_deprecation_warnings
  • test_extract_tar_does_not_emit_a_deprecation_warning
  • test_extract_tar_raw_does_not_emit_a_deprecation_warning
  • test_extract_tar_honors_an_explicit_filter
  • test_extractall_falls_back_on_pythons_without_filters, which simulates a
    Python without tar extraction filters and checks the legacy call path.

test_extract_tar_honors_an_explicit_filter is skipped on Python versions
older than 3.12, where tarfile.FilterError does not exist.

The existing test_time2tstamp_tstamp2time_is_idempotent was updated to build
its datetime without utcnow() as well.

The full commoncode suite was also run locally (406 passed, 12 skipped, 1 failed). The single failure is
tests/test_distro.py::TestDistro::test_parse_os_release, which expects
tests/data/distro/os-release/ubuntu/ubuntu-artful.txt-expected.json. The
ubuntu-artful.txt fixture is a symlink in the repository, checked out as a
plain file on Windows, so this failure is unrelated to this change and
reproduces on unmodified main.

Copilot AI balanced review requested due to automatic review settings November 8, 2026 08:03

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@shashank-tomar0
shashank-tomar0 force-pushed the fix/deprecation-warnings branch from f272a09 to 44c237e Compare November 8, 2026 08:09
* Use a timezone-aware datetime in time2tstamp() and drop the timezone
  to keep returning a naive UTC datetime as before.
* Pass an explicit filter to TarFile.extractall() when supported. This
  silences the Python 3.12+ DeprecationWarning and keeps the historical
  extraction behavior with the "fully_trusted" filter on Python 3.14+.
* Add tests for the timestamps and for tar extraction with and without
  an explicit filter.

Signed-off-by: Shashank Tomar <shashank.tomar912@gmail.com>
@shashank-tomar0
shashank-tomar0 force-pushed the fix/deprecation-warnings branch from 44c237e to 4a5c4ec Compare November 8, 2026 08:13

This branch has not been deployed

No deployments
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.

Fix DeprecationWarning in timeutils.py and archive.py

2 participants