Skip to content

Allow subclassing DateTimes to work as expected#707

Closed
gazpachoking wants to merge 4 commits intopython-pendulum:masterfrom
gazpachoking:allow_subclassing
Closed

Allow subclassing DateTimes to work as expected#707
gazpachoking wants to merge 4 commits intopython-pendulum:masterfrom
gazpachoking:allow_subclassing

Conversation

@gazpachoking
Copy link
Copy Markdown
Contributor

@gazpachoking gazpachoking commented May 5, 2023

Currently if subclassing DateTime, there are many methods which would return a plain DateTime type, rather than the subclassed type.

I made a new DateTime._instance classmethod so as not to change the public interface, which is used by pendulum.instance as well as internally in the DateTime class.

Fixes #203

Pull Request Check List

These changes don't affect using the library directly, only when subclassed externally. Existing tests should ensure internal behavior hasn't changed.

  • Added tests for changed code.
  • Updated documentation for changed code.

@gazpachoking
Copy link
Copy Markdown
Contributor Author

Any way to get some eyes on this? I'd love to get this working.

@sdispater
Copy link
Copy Markdown
Collaborator

Thanks for this PR. This looks good however I integrated this change in #732 which includes improvements to instance(). I co-authored you in this PR as well 🙂

@sdispater sdispater closed this Aug 15, 2023
@gazpachoking
Copy link
Copy Markdown
Contributor Author

Adding the instance method to the class was my preferred method as well, but I didn't want to change the API without blessing. Even more useful that it's public, thanks so much!

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.

pendulum.DateTime using hardcoded pendulum.datetime in methods

2 participants