Skip to content

Enable ruff DTZ002, DTZ006 and DTZ011 (second wave for #13412) - #14602

Open
gauranshahuja wants to merge 1 commit into
internetarchive:masterfrom
gauranshahuja:13412-dtz-wave2
Open

gauranshahuja wants to merge 1 commit into
internetarchive:masterfrom
gauranshahuja:13412-dtz-wave2

Conversation

@gauranshahuja

@gauranshahuja gauranshahuja commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Part of #13412. This is the second DTZ wave, following #14243, which covered DTZ003 and DTZ004.

What changed

This PR selects three more flake8-datetimez rules in pyproject.toml and fixes the 21 call sites they flag:

Rule Call Sites Replacement
DTZ011 date.today() 17 datetime.now(UTC).date()
DTZ002 datetime.today() 2 datetime.now(UTC).replace(tzinfo=None)
DTZ006 datetime.fromtimestamp(ts) 2 datetime.fromtimestamp(ts, tz=UTC), plus .replace(tzinfo=None) where the result is stored or compared as a datetime

Values that were naive datetimes stay naive, the same way #14243 kept them, so nothing stored or compared changes type. Values that were date objects are still date objects.

Behaviour

Each of these calls used the process's local time zone. The repo's Docker and compose files do not set TZ, so the containers they build already run in UTC, and these calls return the same values there as before. The difference shows up only on a machine whose local time zone is not UTC: there, "today" now means the UTC date.

@cclauss: RayBB suggested I check with you before going further. Two questions:

  1. Is UTC the right choice for these local-time calls, or would you rather keep local time?
  2. How would you like the rest split? On master, ruff 0.17.4 reports DTZ001 (88), DTZ005 (83) and DTZ007 (13) after this PR; 109 of those 184 are in tests. My plan was to take DTZ007 next, then DTZ005, then DTZ001, one rule per PR.

Testing

  • ruff check (0.17.4, the version pinned in .pre-commit-config.yaml): no findings in this branch that master doesn't already have. DTZ002, DTZ006 and DTZ011 now report 0.
  • ruff format --check on the changed files passes.
  • pytest on the touched areas (fastapi, utils, upstream, worksearch, coverstore, core, contribute, views, scripts), run on this branch and on master on Windows: the same 2683 pass on both, and the set of failures and errors is identical (all Windows-only, such as fcntl), so the branch adds no new failures. tests/fastapi/test_tasks_stats.py and the utils/dateutil.py doctests pass.

@openlibrary-bot
openlibrary-bot requested a review from a team November 19, 2026 19:11
@github-project-automation github-project-automation Bot moved this to Waiting Review/Merge from Staff in Ray's Project Nov 19, 2026
@openlibrary-bot

Copy link
Copy Markdown
Collaborator

Thanks for the PR, @gauranshahuja!

@RayBB is assigned to this PR and currently has:

  • 27 open PR(s) of equal or higher priority to review first.
PR triage checklist (maintainers / Pierre)
  • PR description — not empty; explains what the change does and how to verify it
  • References an issue — PR body contains a #NNN reference
    • Linked issue is triaged — has a Priority: * label (not just Needs: Triage)
    • Linked issue is assigned — has at least one assignee
  • Commit history clean — no WIP/fixup/conflict noise; commit messages are meaningful
  • CI passing — no failing check-runs
  • Test cases present — if the change touches substantive logic, test coverage exists or is explained
  • Proof of testing — PR body includes a description of what was tested, a screenshot, or a video

Note

This comment was automatically generated by Pierre, Open Library's PR first-touch assistant, on behalf of @mekarpeles. This is NOT a code review or sign-off.

@openlibrary-bot openlibrary-bot 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.

No issues found on 85b4bd6.

🎫 Linked issues 🔶: #13412 🔶

#13412 - Partially compliant

Compliant requirements:

  • Enables DTZ002, DTZ006 and DTZ011 (DTZ003/DTZ004 were already enabled) and fixes every call site they flag

Non-compliant requirements:

  • The blanket "DTZ" selector itself is still commented out in pyproject.toml; only a subset of DTZ rules (002, 003, 004, 006, 011) is enabled, not the full flake8-datetimez rule family (e.g. DTZ001, DTZ005, DTZ007, DTZ012 remain off)

Requires further human verification:

  • Whether pre-commit/CI passes cleanly with the newly enabled rules across the whole repo

A maintainer will review this PR next · How this bot works

@openlibrary-bot openlibrary-bot added the Needs: Rebase Has merge conflicts with the base branch — rebase/update to resolve (auto-managed by olaf) label Nov 19, 2026
@openlibrary-bot
openlibrary-bot requested a review from a team November 20, 2026 06:37

@openlibrary-bot openlibrary-bot 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.

No issues found on c4f1771.

🎫 Linked issues 🔶: #13412 🔶

#13412 - Partially compliant

Compliant requirements:

  • Enables DTZ002 (datetime.today()), DTZ006 (fromtimestamp() without tz), and DTZ011 (date.today()), alongside the already-enabled DTZ003/DTZ004
  • Fixes every call site in the tree that would otherwise violate the newly enabled rules

Non-compliant requirements:

  • The full "DTZ" rule group is still commented out in pyproject.toml; rules like DTZ001, DTZ005, DTZ007, DTZ012 remain disabled

Requires further human verification:

  • Whether pre-commit/CI actually passes with these rules enabled
  • Whether the targeted pytest warnings are gone

A maintainer will review this PR next · How this bot works

@openlibrary-bot openlibrary-bot removed the Needs: Rebase Has merge conflicts with the base branch — rebase/update to resolve (auto-managed by olaf) label Nov 20, 2026
@RayBB

RayBB commented Nov 20, 2026

Copy link
Copy Markdown
Collaborator

@cclauss would you be willing to take a look at this one?

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

Status: Waiting Review/Merge from Staff

Development

Successfully merging this pull request may close these issues.

3 participants