fix: correct enforce_tz repr in IsDatetime#128
Closed
Bojun-Vvibe wants to merge 1 commit intosamuelcolvin:mainfrom
Closed
fix: correct enforce_tz repr in IsDatetime#128Bojun-Vvibe wants to merge 1 commit intosamuelcolvin:mainfrom
Bojun-Vvibe wants to merge 1 commit intosamuelcolvin:mainfrom
Conversation
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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Repo: samuelcolvin/dirty-equals (⭐ 900)
Type: bugfix
Files changed: 2
Lines: +6/-1
What
In
dirty_equals/_datetime.py, theIsDatetime.__init__method sets_repr_kwargsfor the
enforce_tzargument but incorrectly referencesformat_stringas thedisplayed value (
enforce_tz=Omit if enforce_tz is True else format_string).This means when
enforce_tz=Falseis passed, the repr shows the value offormat_string(oftenNone) under theenforce_tzkey instead ofFalse.The fix uses
enforce_tzas 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 debuggingfailed assertions, which is the main purpose of
dirty-equals.Testing
test_repr_enforce_tz_falseintests/test_datetime.py.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.