mypy complains about ABC service #97
-
Here's some code: from abc import ABC, abstractmethod
from dataclasses import dataclass
from decimal import Decimal
import svcs
from typing_extensions import override
@dataclass
class Transaction:
id: str
amount: Decimal
class Service(ABC):
@abstractmethod
def create_transaction(self, *, id: str, amount: Decimal) -> Transaction: ...
class ServiceImpl(Service):
@override
def create_transaction(self, *, id: str, amount: Decimal) -> Transaction:
return Transaction(id, amount)
REGISTRY = svcs.Registry()
REGISTRY.register_factory(Service, ServiceImpl)
def main() -> None:
container = svcs.Container(REGISTRY)
service = container.get(Service)
print(service.create_transaction(id="id1", amount=Decimal(100)))
if __name__ == "__main__":
main() This code registers
Any advice? |
Beta Was this translation helpful? Give feedback.
Answered by
hynek
Jul 30, 2024
Replies: 1 comment
-
That’s sounds like https://svcs.hynek.me/en/stable/typing-caveats.html |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
gjcarneiro
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
That’s sounds like https://svcs.hynek.me/en/stable/typing-caveats.html