Skip to content

Commit

Permalink
Make example in documentation runnable (#247)
Browse files Browse the repository at this point in the history
With all required imports and `NewType` declarations.
  • Loading branch information
np-kyokyo authored Jan 24, 2024
1 parent dc5081d commit 44ac4e0
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions docs/terminology.rst
Original file line number Diff line number Diff line change
Expand Up @@ -78,22 +78,25 @@ 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
def __init__(self, name: Name, description: Description):
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
Expand Down

0 comments on commit 44ac4e0

Please sign in to comment.