tags:

views:

217

answers:

2

As I understand it, Python (2.5.2) does not have real support for abstract classes. Why is pylint complaining about this class being an "Abstract class not reference?" Will it do this for any class that has NotImplementedError thrown?

I have each class in its own file so if this is the case I guess I have no choice but to suppress this message but I am hoping there is maybe another way around it.

"""Package Repository interface."""


class PackageRepository(object):
    """Package Repository interface."""

    def __init__(self):
        self.hello = "world"

    def get_package(self, package_id):
        """
        Get a package by ID.
        """
        raise NotImplementedError( \
                "get_package() method has not been implemented")

    def get_packages(self):
        """
        Get all packages.
        """
        raise NotImplementedError( \
                "get_packages() method has not been implemented")

    def commit(self):
        """
        Commit all changes.
        """
        raise NotImplementedError( \
                "commit() method has not been implemented")

    def do_something(self):
        """
        Doing something.
        """
        return self.hello

EDIT

Perhaps I should clarify. I realize this is an abstract class and I would love to use the abstract keyword but as I understand it none of that matters in Python (at least in the version I am currently using) so I didn't bother doing any funny abstract tricks (like those found here) and simply left it out.

I was surprised to see that pylint picks up on the fact that this is an abstract class on its own. What makes pylint determine this is an abstract class? Is it simply looking for NotImplementedError being thrown somewhere?

A: 

In my experience, pylint is a bit over-zealous, and isn't useful until you've turned off a number of the warnings.

Ned Batchelder
+3  A: 

FWIW, raising NotImplementedError is enough to make pylint think this is an abstract class (which is absolutely correct). from logilab.org/card/pylintfeatures: W0223: Method %r is abstract in class %r but is not overridden Used when an abstract method (ie raise NotImplementedError) is not overridden in concrete class. – Tobiesque 2 hours ago

S.Lott
Hint to @Tobiesque: Post your answer and get the reputation. That way I can delete this answer in favor of yours.
S.Lott