ksindi / implements

:snake: Pythonic interfaces using decorators
http://implements.readthedocs.io/
Apache License 2.0
33 stars 4 forks source link

Validate staticmethod and classmethod #11

Closed pshirali closed 4 years ago

pshirali commented 4 years ago

Verification of staticmethod and classmethod is currently limited to signature checks. This permits the following code:

Actual

With staticmethod:

class FooInterface(Interface):
    @staticmethod
    def foo(a, b):
        pass

@implements(FooInterface)
class FooImplementation:
    def foo(a, b):          # missing staticmethod decorator in implementation
        pass

With classmethod:

class FooInterface(Interface):
    @classmethod
    def foo(cls, a, b):     # inspect.signature drops first arg, so signature is (a, b)
        pass

@implements(FooInterface)
class FooImplementation:
    @staticmethod           # could be staticmethod, or no decorator (regular method)
    def foo(a, b):          # signature matches that of classmethod foo(cls, a, b)
        pass

Expected Enhance implements to enforce staticmethod and classmethod on the implementation.