require-explicit-contract-implementation
Require owned substitutes to inherit an injected nominal abstract contract.
Why
An ABC is a nominal contract: inheriting it makes its abstract operations enforceable at instantiation. Protocols intentionally use structural typing and do not require inheritance.
Fix
Make the owned implementation inherit the nominal ABC expected by the consumer.
Examples
# packagefrom abc import ABC, abstractmethod
class Publisher(ABC): @abstractmethod def publish(self) -> None: ...
class Consumer: def __init__(self, publisher: Publisher) -> None: self.publisher = publisherclass FakePublisher: def publish(self) -> None: ...from app.consumer import Consumerfrom app.fake import FakePublisher
def setup() -> None: Consumer(publisher=FakePublisher())# packagefrom abc import ABC, abstractmethod
class Publisher(ABC): @abstractmethod def publish(self) -> None: ...
class Consumer: def __init__(self, publisher: Publisher) -> None: self.publisher = publisherfrom app.consumer import Publisher
class FakePublisher(Publisher): def publish(self) -> None: ...from app.consumer import Consumerfrom app.fake import FakePublisher
def setup() -> None: Consumer(publisher=FakePublisher())