Skip to content

fix: correct enforce_tz repr in IsDatetime#128

Closed
Bojun-Vvibe wants to merge 1 commit intosamuelcolvin:mainfrom
Bojun-Vvibe:agent/samuelcolvin_dirty-equals-1776714999
Closed

fix: correct enforce_tz repr in IsDatetime#128
Bojun-Vvibe wants to merge 1 commit intosamuelcolvin:mainfrom
Bojun-Vvibe:agent/samuelcolvin_dirty-equals-1776714999

Conversation

@Bojun-Vvibe
Copy link
Copy Markdown

Repo: samuelcolvin/dirty-equals (⭐ 900)
Type: bugfix
Files changed: 2
Lines: +6/-1

What

In dirty_equals/_datetime.py, the IsDatetime.__init__ method sets _repr_kwargs
for the enforce_tz argument but incorrectly references format_string as the
displayed value (enforce_tz=Omit if enforce_tz is True else format_string).
This means when enforce_tz=False is passed, the repr shows the value of
format_string (often None) under the enforce_tz key instead of False.
The fix uses enforce_tz as intended. A new test asserts the repr.

Why

The bug silently produces misleading reprs (e.g., IsDatetime(..., enforce_tz=None)
when the user passed enforce_tz=False). Accurate reprs matter for debugging
failed assertions, which is the main purpose of dirty-equals.

Testing

  • Added test_repr_enforce_tz_false in tests/test_datetime.py.
  • Ran pytest tests/test_datetime.py::test_repr tests/test_datetime.py::test_repr_enforce_tz_false — both pass.

Risk

Low — one-line fix to a repr formatting expression with a targeted new test; no behavior change to equality logic.

The _repr_kwargs entry for enforce_tz was incorrectly set to format_string,
causing misleading reprs when enforce_tz=False was passed (e.g. format_string's
value would appear in the repr instead of False).
@Bojun-Vvibe Bojun-Vvibe closed this by deleting the head repository Apr 21, 2026
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.

2 participants