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

feat: consider decorating parent class methods with @abstractmethod #45

Open
martintb opened this issue Jan 19, 2023 · 0 comments
Open

Comments

@martintb
Copy link
Collaborator

We should consider whether our abstract classes, which are used to define API interfaces, should be made to be strict. By using the @AbstractMethod decorator from the abc module of the standard library, you can force derived classes to implement a defined interface.

For example, if we want loading.SyringePump.SyringePump to always have a withdraw and dispense:

from abc import ABC, abstractmethod

class SyringePump(ABC):

     def stop(self):
        raise NotImplementedError

    @abstractmethod    
    def withdraw(self,volume,block=True):
        pass

    @abstractmethod
    def dispense(self,volume,block=True):
        pass
        
    def setRate(self,rate):
        raise NotImplementedError

    def getRate(self,rate):
        raise NotImplementedError

    def emptySyringe(self):
        raise NotImplementedError

See here for a discussion on abstract classes including why they're sometimes better than the NotImplementedError method we currently use.

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

No branches or pull requests

1 participant