mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2024-11-25 19:14:00 +03:00
Update example docblocks
This commit is contained in:
parent
53f692a78c
commit
607e51e218
|
@ -91,16 +91,16 @@ Examples
|
||||||
"""Catalog of service providers."""
|
"""Catalog of service providers."""
|
||||||
|
|
||||||
database = di.Singleton(sqlite3.connect, ':memory:')
|
database = di.Singleton(sqlite3.connect, ':memory:')
|
||||||
""":type: () -> sqlite3.Connection"""
|
""":type: di.Provider -> sqlite3.Connection"""
|
||||||
|
|
||||||
users = di.Factory(UsersService,
|
users = di.Factory(UsersService,
|
||||||
db=database)
|
db=database)
|
||||||
""":type: () -> UsersService"""
|
""":type: di.Provider -> UsersService"""
|
||||||
|
|
||||||
auth = di.Factory(AuthService,
|
auth = di.Factory(AuthService,
|
||||||
db=database,
|
db=database,
|
||||||
users_service=users)
|
users_service=users)
|
||||||
""":type: () -> AuthService"""
|
""":type: di.Provider -> AuthService"""
|
||||||
|
|
||||||
|
|
||||||
# Retrieving catalog providers:
|
# Retrieving catalog providers:
|
||||||
|
|
|
@ -39,7 +39,7 @@ from .utils import ensure_is_catalog_bundle
|
||||||
from .errors import Error
|
from .errors import Error
|
||||||
|
|
||||||
|
|
||||||
VERSION = '0.10.2'
|
VERSION = '0.10.3'
|
||||||
|
|
||||||
|
|
||||||
__all__ = (
|
__all__ = (
|
||||||
|
|
|
@ -9,7 +9,7 @@ that is standard naming convention for attribute names in Python.
|
||||||
|
|
||||||
.. note::
|
.. note::
|
||||||
|
|
||||||
It might be useful to add such ``""":type: (di.Provider) -> Object1"""``
|
It might be useful to add such ``""":type: di.Provider -> Object1"""``
|
||||||
docstrings just on the next line after provider's definition. It will
|
docstrings just on the next line after provider's definition. It will
|
||||||
help code analyzing tools and IDE's to understand that variable above
|
help code analyzing tools and IDE's to understand that variable above
|
||||||
contains some callable object, that returns particular instance as a
|
contains some callable object, that returns particular instance as a
|
||||||
|
|
|
@ -7,6 +7,10 @@ that were made in every particular version.
|
||||||
From version 0.7.6 *Dependency Injector* framework strictly
|
From version 0.7.6 *Dependency Injector* framework strictly
|
||||||
follows `Semantic versioning`_
|
follows `Semantic versioning`_
|
||||||
|
|
||||||
|
0.10.3
|
||||||
|
------
|
||||||
|
- Update example docblocks.
|
||||||
|
|
||||||
0.10.2
|
0.10.2
|
||||||
------
|
------
|
||||||
- Fix bug with injecting entities that implement ``__getattr__``.
|
- Fix bug with injecting entities that implement ``__getattr__``.
|
||||||
|
|
|
@ -1,9 +1,6 @@
|
||||||
"""Config provider examples."""
|
"""Config provider examples."""
|
||||||
|
|
||||||
from dependency_injector.catalog import AbstractCatalog
|
import dependency_injector as di
|
||||||
from dependency_injector.providers import Config
|
|
||||||
from dependency_injector.providers import Factory
|
|
||||||
from dependency_injector.injections import KwArg
|
|
||||||
|
|
||||||
|
|
||||||
class ObjectA(object):
|
class ObjectA(object):
|
||||||
|
@ -16,17 +13,17 @@ class ObjectA(object):
|
||||||
self.timezone = timezone
|
self.timezone = timezone
|
||||||
|
|
||||||
|
|
||||||
class Catalog(AbstractCatalog):
|
class Catalog(di.AbstractCatalog):
|
||||||
"""Catalog of dependency_injector providers."""
|
"""Catalog of providers."""
|
||||||
|
|
||||||
config = Config()
|
config = di.Config()
|
||||||
""":type: (dependency_injector.Config)"""
|
""":type: di.Config"""
|
||||||
|
|
||||||
object_a = Factory(ObjectA,
|
object_a = di.Factory(ObjectA,
|
||||||
KwArg('fee', config.FEE),
|
fee=config.FEE,
|
||||||
KwArg('price', config.PRICE),
|
price=config.PRICE,
|
||||||
KwArg('timezone', config.GLOBAL.TIMEZONE))
|
timezone=config.GLOBAL.TIMEZONE)
|
||||||
""":type: (dependency_injector.Provider) -> ObjectA"""
|
""":type: di.Provider -> ObjectA"""
|
||||||
|
|
||||||
|
|
||||||
# Setting config value and making some tests.
|
# Setting config value and making some tests.
|
||||||
|
|
|
@ -11,13 +11,13 @@ class Services(di.AbstractCatalog):
|
||||||
"""Example catalog of service providers."""
|
"""Example catalog of service providers."""
|
||||||
|
|
||||||
users = di.Factory(services.UsersService)
|
users = di.Factory(services.UsersService)
|
||||||
""":type: (di.Provider) -> services.UsersService"""
|
""":type: di.Provider -> services.UsersService"""
|
||||||
|
|
||||||
auth = di.Factory(services.AuthService)
|
auth = di.Factory(services.AuthService)
|
||||||
""":type: (di.Provider) -> services.AuthService"""
|
""":type: di.Provider -> services.AuthService"""
|
||||||
|
|
||||||
photos = di.Factory(services.PhotosService)
|
photos = di.Factory(services.PhotosService)
|
||||||
""":type: (di.Provider) -> services.PhotosService"""
|
""":type: di.Provider -> services.PhotosService"""
|
||||||
|
|
||||||
|
|
||||||
# Declaring views catalog:
|
# Declaring views catalog:
|
||||||
|
@ -27,12 +27,12 @@ class Views(di.AbstractCatalog):
|
||||||
auth = di.Factory(views.AuthView,
|
auth = di.Factory(views.AuthView,
|
||||||
services=Services.Bundle(Services.users,
|
services=Services.Bundle(Services.users,
|
||||||
Services.auth))
|
Services.auth))
|
||||||
""":type: (di.Provider) -> views.AuthView"""
|
""":type: di.Provider -> views.AuthView"""
|
||||||
|
|
||||||
photos = di.Factory(views.PhotosView,
|
photos = di.Factory(views.PhotosView,
|
||||||
services=Services.Bundle(Services.users,
|
services=Services.Bundle(Services.users,
|
||||||
Services.photos))
|
Services.photos))
|
||||||
""":type: (di.Provider) -> views.PhotosView"""
|
""":type: di.Provider -> views.PhotosView"""
|
||||||
|
|
||||||
|
|
||||||
# Creating example views:
|
# Creating example views:
|
||||||
|
|
|
@ -7,14 +7,14 @@ class CatalogA(di.AbstractCatalog):
|
||||||
"""Example catalog A."""
|
"""Example catalog A."""
|
||||||
|
|
||||||
provider1 = di.Factory(object)
|
provider1 = di.Factory(object)
|
||||||
""":type: (di.Provider) -> object"""
|
""":type: di.Provider -> object"""
|
||||||
|
|
||||||
|
|
||||||
class CatalogB(CatalogA):
|
class CatalogB(CatalogA):
|
||||||
"""Example catalog B."""
|
"""Example catalog B."""
|
||||||
|
|
||||||
provider2 = di.Singleton(object)
|
provider2 = di.Singleton(object)
|
||||||
""":type: (di.Provider) -> object"""
|
""":type: di.Provider -> object"""
|
||||||
|
|
||||||
|
|
||||||
# Making some asserts for `providers` attribute:
|
# Making some asserts for `providers` attribute:
|
||||||
|
|
|
@ -16,18 +16,18 @@ class Catalog(di.AbstractCatalog):
|
||||||
object1_factory = di.Factory(Object1,
|
object1_factory = di.Factory(Object1,
|
||||||
arg1=1,
|
arg1=1,
|
||||||
arg2=2)
|
arg2=2)
|
||||||
""":type: (di.Provider) -> Object1"""
|
""":type: di.Provider -> Object1"""
|
||||||
|
|
||||||
object2_factory = di.Factory(Object2,
|
object2_factory = di.Factory(Object2,
|
||||||
object1=object1_factory)
|
object1=object1_factory)
|
||||||
""":type: (di.Provider) -> Object2"""
|
""":type: di.Provider -> Object2"""
|
||||||
|
|
||||||
|
|
||||||
class AnotherCatalog(di.AbstractCatalog):
|
class AnotherCatalog(di.AbstractCatalog):
|
||||||
"""Another providers catalog."""
|
"""Another providers catalog."""
|
||||||
|
|
||||||
object2_factory = di.Factory(ExtendedObject2)
|
object2_factory = di.Factory(ExtendedObject2)
|
||||||
""":type: (di.Provider) -> ExtendedObject2"""
|
""":type: di.Provider -> ExtendedObject2"""
|
||||||
|
|
||||||
|
|
||||||
# Overriding `Catalog` with `AnotherCatalog`:
|
# Overriding `Catalog` with `AnotherCatalog`:
|
||||||
|
|
|
@ -16,11 +16,11 @@ class Catalog(di.AbstractCatalog):
|
||||||
object1_factory = di.Factory(Object1,
|
object1_factory = di.Factory(Object1,
|
||||||
arg1=1,
|
arg1=1,
|
||||||
arg2=2)
|
arg2=2)
|
||||||
""":type: (di.Provider) -> Object1"""
|
""":type: di.Provider -> Object1"""
|
||||||
|
|
||||||
object2_factory = di.Factory(Object2,
|
object2_factory = di.Factory(Object2,
|
||||||
object1=object1_factory)
|
object1=object1_factory)
|
||||||
""":type: (di.Provider) -> Object2"""
|
""":type: di.Provider -> Object2"""
|
||||||
|
|
||||||
|
|
||||||
# Overriding `Catalog` with `AnotherCatalog`:
|
# Overriding `Catalog` with `AnotherCatalog`:
|
||||||
|
@ -29,7 +29,7 @@ class AnotherCatalog(di.AbstractCatalog):
|
||||||
"""Another providers catalog."""
|
"""Another providers catalog."""
|
||||||
|
|
||||||
object2_factory = di.Factory(ExtendedObject2)
|
object2_factory = di.Factory(ExtendedObject2)
|
||||||
""":type: (di.Provider) -> ExtendedObject2"""
|
""":type: di.Provider -> ExtendedObject2"""
|
||||||
|
|
||||||
|
|
||||||
# Creating some objects using overridden catalog:
|
# Creating some objects using overridden catalog:
|
||||||
|
|
|
@ -7,10 +7,10 @@ class Catalog(di.AbstractCatalog):
|
||||||
"""Providers catalog."""
|
"""Providers catalog."""
|
||||||
|
|
||||||
factory1 = di.Factory(object)
|
factory1 = di.Factory(object)
|
||||||
""":type: (di.Provider) -> object"""
|
""":type: di.Provider -> object"""
|
||||||
|
|
||||||
factory2 = di.Factory(object)
|
factory2 = di.Factory(object)
|
||||||
""":type: (di.Provider) -> object"""
|
""":type: di.Provider -> object"""
|
||||||
|
|
||||||
# Creating some objects:
|
# Creating some objects:
|
||||||
object1 = Catalog.factory1()
|
object1 = Catalog.factory1()
|
||||||
|
|
|
@ -25,16 +25,16 @@ class Services(di.AbstractCatalog):
|
||||||
"""Catalog of service providers."""
|
"""Catalog of service providers."""
|
||||||
|
|
||||||
database = di.Singleton(sqlite3.connect, ':memory:')
|
database = di.Singleton(sqlite3.connect, ':memory:')
|
||||||
""":type: () -> sqlite3.Connection"""
|
""":type: di.Provider -> sqlite3.Connection"""
|
||||||
|
|
||||||
users = di.Factory(UsersService,
|
users = di.Factory(UsersService,
|
||||||
db=database)
|
db=database)
|
||||||
""":type: () -> UsersService"""
|
""":type: di.Provider -> UsersService"""
|
||||||
|
|
||||||
auth = di.Factory(AuthService,
|
auth = di.Factory(AuthService,
|
||||||
db=database,
|
db=database,
|
||||||
users_service=users)
|
users_service=users)
|
||||||
""":type: () -> AuthService"""
|
""":type: di.Provider -> AuthService"""
|
||||||
|
|
||||||
|
|
||||||
# Retrieving catalog providers:
|
# Retrieving catalog providers:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user