Skip to content

Reject bool in datetime/date/duration integer fields - #1011

Open
Pitchfork-and-Torch wants to merge 1 commit into
python-pendulum:masterfrom
Pitchfork-and-Torch:cook/reject-bool-datetime-duration-fields
Open

Pitchfork-and-Torch wants to merge 1 commit into
python-pendulum:masterfrom
Pitchfork-and-Torch:cook/reject-bool-datetime-duration-fields

Conversation

@Pitchfork-and-Torch

Copy link
Copy Markdown

Summary

bool is a subclass of int, so dt.replace(year=True) became year 1 and dt.add(days=True) added one day. Reject bool in add/set/replace and Duration construction. The tzinfo=True sentinel for keeping the current timezone is unchanged.

Bug

>>> import pendulum
>>> pendulum.datetime(2020, 5, 15).replace(year=True)
DateTime(1, 5, 15, ...)  # unexpected
>>> pendulum.datetime(2020, 5, 15).add(days=True)
DateTime(2020, 5, 16, ...)  # unexpected +1 day
>>> pendulum.duration(years=True)
Duration(days=365)  # unexpected

Test plan

  • test_add_rejects_bool / test_replace_rejects_bool / test_set_rejects_bool
  • test_duration_rejects_bool
  • test_replace_tzinfo_true_still_allowed
  • Date add/replace bool rejects

bool is a subclass of int, so year=True became year 1 and
days=True added one day. Reject bool in add/set/replace and
Duration construction; tzinfo=True sentinel is unchanged.
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.

1 participant