Skip to content
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

Factor out common logic in API functions #41

Open
asmeurer opened this issue Jun 15, 2020 · 0 comments
Open

Factor out common logic in API functions #41

asmeurer opened this issue Jun 15, 2020 · 0 comments

Comments

@asmeurer
Copy link
Member

A lot of API functions have common logic at the top of each implementation. For example, calling ndindex() on the input arguments, or type checking that is the same in every case.

We should refactor the common logic to the superclass, and have the methods call implementations in the subclasses. Something like

class NDIndex:
    def method(self, arg):
       # common logic goes here

       return self._method(arg)

    def _method(self, arg):
        raise NotImplementedError
class Subclass(NDIndex):
    def _method(self, arg):
        # Subclass specific implementation

The only downside of this is that it makes it impossible to have subclass specific docstrings. Presently reduce and expand are the only methods with subclass specific docstrings, and I don't think they have any common logic, so they can be left alone. For other methods, we could have some way to automatically replace the docstrings with docstrings on the implementation methods.

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

No branches or pull requests

2 participants