Skip to content

Commit 44ac4e0

Browse files
authored
Make example in documentation runnable (#247)
With all required imports and `NewType` declarations.
1 parent dc5081d commit 44ac4e0

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

docs/terminology.rst

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,22 +78,25 @@ Injection is the process of providing an instance of a type, to a method that us
7878

7979
Here is an example of injection on a module provider method, and on the constructor of a normal class::
8080

81-
from injector import inject
81+
from typing import NewType
82+
83+
from injector import Binder, Module, inject, provider
84+
85+
Name = NewType("Name", str)
86+
Description = NewType("Description", str)
8287

8388
class User:
8489
@inject
8590
def __init__(self, name: Name, description: Description):
8691
self.name = name
8792
self.description = description
8893

89-
9094
class UserModule(Module):
91-
def configure(self, binder):
95+
def configure(self, binder: Binder):
9296
binder.bind(User)
9397

94-
9598
class UserAttributeModule(Module):
96-
def configure(self, binder):
99+
def configure(self, binder: Binder):
97100
binder.bind(Name, to='Sherlock')
98101

99102
@provider

0 commit comments

Comments
 (0)