#!/usr/local/cpython-3.6/bin/python3 """Rather poor example of using pylint Abstract Base Classes.""" import abc class Polygon: """Polygon class.""" __metaclass__ = abc.ABCMeta @abc.abstractmethod def num_sides(self): """Return number of sides this polygon has.""" pass @abc.abstractmethod def color(self): """Return color of this polygon.""" pass @abc.abstractmethod def perimeter(self): """Return the perimeter of this polygon.""" pass class RedSquare(Polygon): """ A class for a red square. In real life, this would probably be an instance, not a class. """ @staticmethod def num_sides(): """We have 4 sides.""" return 4 @staticmethod def color(): """We are red.""" return 'Red' @staticmethod def perimeter(): """Return the perimeter of the square.""" return 4 class BlueTriangle(Polygon): """ A class for a blue triangle. In real life, this would probably be an instance, not a class. """ @staticmethod def num_sides(): """We have 3 sides.""" return 3 @staticmethod def color(): """We are blue.""" return 'Blue' # Note that we have no perimeter method - and yet pylint doesn't complain :-S def main(): """Main function.""" list_ = [RedSquare(), BlueTriangle()] for element in list_: print(element.num_sides()) print(element.color()) # Pylint 1.7.1 correctly detects that perimeter is not part of BlueTriangle print(element.perimeter()) main()