Skip to content

fix: correct type() misuse, unused imports, exit(), and timezone-naiv…#2139

Open
Acuspeedster wants to merge 1 commit into
oscal-compass:developfrom
Acuspeedster:fix/misc-bugs-type-check-unused-imports-exit-tz
Open

fix: correct type() misuse, unused imports, exit(), and timezone-naiv…#2139
Acuspeedster wants to merge 1 commit into
oscal-compass:developfrom
Acuspeedster:fix/misc-bugs-type-check-unused-imports-exit-tz

Conversation

@Acuspeedster

Copy link
Copy Markdown
Contributor

fix: correct type() misuse, unused imports, exit(), and timezone-naive
datetime

  • jinja/tags.py: replace type(x is str) with isinstance(x, str).
    type(kwargs['format'] is str) always evaluated to <class 'bool'>
    (truthy), making the else branch (default format fallback)
    unreachable dead code and silently passing non-string values to
    strftime().

  • catalog_merger.py: remove 7 unused list_utils imports that were
    never used (as_dict, as_filtered_list, as_list,
    delete_item_from_list, deep_set, get_item_from_list,
    none_if_empty). Only set_or_pop is actually referenced.

  • cli.py: replace exit() with sys.exit(). The built-in exit() is
    intended for interactive interpreter use; sys.exit() is correct
    for application code. Added missing import sys.

  • cache.py: pass tz=datetime.timezone.utc to both fromtimestamp()
    and now() so the timedelta calculation is timezone-aware and
    immune to DST transitions.


Types of changes

<!--- What types of changes does your code introduce? Put an `x` in all the boxes that apply: -->
  • Hot fix (emergency fix and release)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Documentation (change which affects the documentation site)
  • Breaking change (fix or feature that would cause existing
    functionality to change)
  • Release (develop -> main)

Quality assurance (all should be covered).

  • My code follows the code style of this project.
  • Documentation for my change is up to date?
  • My PR meets testing requirements.
  • All new and existing tests passed.
  • All commits are signed-off.

How To Test

If using act (https://github.com/nektos/act), fill in below:

Summary

Four independent bug fixes identified during static analysis. These
changes correct logic errors, remove dead imports, ensure correct
program exit behavior, and make datetime arithmetic timezone-safe. No
functional changes beyond fixing the identified bugs.

Files changed


File Change
trestle/core/jinja/tags.py type(x is str)isinstance(x, str)
trestle/core/catalog/catalog_merger.py Remove unused list_utils imports
trestle/cli.py Replace exit() with sys.exit()
trestle/core/remote/cache.py Use datetime.timezone.utc for datetime arithmetic

Testing

  • Existing Jinja and cache tests pass
  • ruff check clean for modified files
  • Changes affect already-covered code paths

Key links:

Before you merge

  • Ensure it is a 'squash commit' if not a release.
  • Ensure CI is currently passing
  • Check sonar. If you are working for a fork a maintainer will reach
    out, if required.

…e datetime

- jinja/tags.py: replace type(x is str) with isinstance(x, str).
  type(kwargs['format'] is str) always evaluated to <class 'bool'> (truthy),
  making the else branch (default format fallback) unreachable dead code and
  silently passing non-string values to strftime().

- catalog_merger.py: remove 7 list_utils imports that were never used
  (as_dict, as_filtered_list, as_list, delete_item_from_list, deep_set,
  get_item_from_list, none_if_empty). Only set_or_pop is actually called.

- cli.py: replace exit() with sys.exit(). The built-in exit() is intended
  for interactive interpreter use; sys.exit() is correct for application code.
  Add missing 'import sys'.

- cache.py: pass tz=datetime.timezone.utc to both fromtimestamp() and now()
  so the timedelta calculation is timezone-aware and immune to DST transitions.

Signed-off-by: Acuspeedster <arnavrajsingh@gmail.com>
@Acuspeedster Acuspeedster requested a review from a team as a code owner March 11, 2026 15:07
@Acuspeedster

Copy link
Copy Markdown
Contributor Author

@butler54 butler54 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please fix the merge conflicts and re-request review.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants