'Is it possible to enforce a return type with an interface using python ABC?
Say I have the following code sample. I want the 'walk' function to return a dictionary for all animals, I am using the interface to enforce this. However, below code sample will run just fine. Is it possible to modify the interface so that it enforces a return type of dict (not allowing me to run this code sample)?
from abc import ABC, abstractmethod
class Animal(ABC):
@abstractmethod
def walk(self) -> dict:
return dict
class Cat(Animal):
def walk(self) -> None:
print("Walking")
cat = Cat()
position = cat.walk()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
