Skip to content

INT: take DateOffset out of the inheritance tree for BaseOffset subclasses #34147

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
May 13, 2020

Conversation

jbrockmendel
Copy link
Member

Use a __instancecheck__ override to keep isinstance checks working.

This will allow us to start moving other BaseOffset subclasses up into liboffsets without having to get DateOffset (which will be one of the trickiest) first.

@jreback jreback added the Frequency DateOffsets label May 13, 2020
@jreback jreback added this to the 1.1 milestone May 13, 2020
@jreback jreback merged commit 537ab5a into pandas-dev:master May 13, 2020
@jbrockmendel jbrockmendel deleted the ref-liboffsets-inits branch May 13, 2020 15:38
return isinstance(obj, BaseOffset)

@classmethod
def __subclasscheck__(cls, obj) -> bool:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@simonjayhawkins is this going to mess up annotations elsewhere we annotate something as a DateOffset?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mypy is a static checker, so IIUC mypy doesn't execute the code in __instancecheck__ and __subclasscheck__. Therefore, mypy has no way of knowing that BaseOffset subclass pretend to be DateOffset subclasses.

This is probably a use case for Protocol. i.e. structural typing instead of nominal typing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Frequency DateOffsets
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants