Skip to content

Flag incomplete implementation on class def instead of instantiation? #4

@mthuurne

Description

@mthuurne

From the README:

class IAnimal(zope.interface.Interface):
    def say() -> None:
        pass

@zope.interface.implementer(IAnimal)
class Cow(object):
    def say(self) -> None:
        print("Moooo")

The interface IAnimal will be treated as an abstract base class of the implementation Cow: you will not be able to instantiate Cow if interface implementation is incomplete. Incompatible method signatures will be reported as well.

If Cow states it implements IAnimal, and it doesn't implement say(), wouldn't that be an error even if Cow is never instantiated? In other words, I think this error could reported on the class definition instead of on instantiation.

Reporting the error on the implementer's class definition would be an advantage in code bases that don't have 100% type checking coverage: if the code that instantiates the implementer is inside a function that lacks type annotations, mypy will skip that code and the incomplete interface implementation will not be reported.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions