From 44ac4e0b09daeb5788eb0944cb32e7e815bcd092 Mon Sep 17 00:00:00 2001 From: np-kyokyo <119554975+np-kyokyo@users.noreply.github.com> Date: Thu, 25 Jan 2024 00:21:13 +0900 Subject: [PATCH] Make example in documentation runnable (#247) With all required imports and `NewType` declarations. --- docs/terminology.rst | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/docs/terminology.rst b/docs/terminology.rst index 26bc8ed..6e34535 100644 --- a/docs/terminology.rst +++ b/docs/terminology.rst @@ -78,7 +78,12 @@ Injection is the process of providing an instance of a type, to a method that us Here is an example of injection on a module provider method, and on the constructor of a normal class:: - from injector import inject + from typing import NewType + + from injector import Binder, Module, inject, provider + + Name = NewType("Name", str) + Description = NewType("Description", str) class User: @inject @@ -86,14 +91,12 @@ Here is an example of injection on a module provider method, and on the construc self.name = name self.description = description - class UserModule(Module): - def configure(self, binder): + def configure(self, binder: Binder): binder.bind(User) - class UserAttributeModule(Module): - def configure(self, binder): + def configure(self, binder: Binder): binder.bind(Name, to='Sherlock') @provider