Skip to content

Use @abstractmethod inside of abstract classes #1837

@septatrix

Description

@septatrix
$ grep NotImplementedError -r telegram --exclude-dir=vendor -I --line-number
./telegram/ext/handler.py:        raise NotImplementedError
./telegram/ext/basepersistence.py:        raise NotImplementedError
./telegram/ext/basepersistence.py:        raise NotImplementedError
./telegram/ext/basepersistence.py:        raise NotImplementedError
./telegram/ext/basepersistence.py:        raise NotImplementedError
./telegram/ext/basepersistence.py:        raise NotImplementedError
./telegram/ext/basepersistence.py:        raise NotImplementedError
./telegram/ext/basepersistence.py:        raise NotImplementedError
./telegram/ext/basepersistence.py:        raise NotImplementedError
./telegram/ext/filters.py:        raise NotImplementedError

Whilst looking through the code I noticed a few occurrences where the docstring states that methods must be overwritten/implemented und corresponding checks are apparently in the tests. However Python provides the @abstractmethod decorator which we could use. We could either use the ABCMeta metaclass for this or I could implement this into the Python3 only branch where we could simple inherit ABC.
I think this change would make the code a bit more clear and prevents common pitfalls where one wants to inherit such classes but forgets to implement these methods (probably most common with BasePersistence)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions