Skip to content

Fix diff() typing to accept DateTime (closes #823) - #1087

Open
zheng-guannan577 wants to merge 1 commit into
python-pendulum:masterfrom
zheng-guannan577:fix-pendulum-823
Open

zheng-guannan577 wants to merge 1 commit into
python-pendulum:masterfrom
zheng-guannan577:fix-pendulum-823

Conversation

@zheng-guannan577

Copy link
Copy Markdown

Closes #823: #823

Typing gap

DateTime.diff() previously declared its parameter as datetime.datetime | None. Passing a Pendulum DateTime (the library's own datetime type, and the type diff() is documented to compare) could therefore be flagged by type checkers/linters, even though it works at runtime.

Change

In src/pendulum/datetime.py only, widen the parameter type to:

def diff(self, dt: DateTime | datetime.datetime | None = None, abs: bool = True) -> Interval[datetime.datetime]:

This is a typing-only change. No runtime logic, no other files, and no behaviour change.

Verification (honest note)

Full repo pytest was NOT run locally, because local 3.3.0 needs a Rust extension built with cargo which is not installed. No local test run is claimed beyond the GitHub web editor view; CI must verify the full test suite and typing.

  • Added tests for changed code (not applicable: typing-only change, no runtime behaviour change)
  • Updated documentation for changed code (not applicable: typing-only change)

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

None yet

Development

Successfully merging this pull request may close these issues.

Add DateTime to typing for diff()

1 participant