mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2025-01-31 03:36:41 +03:00
Fix bug with injecting entities with __getattr__ implementations
This commit is contained in:
parent
a42fefacef
commit
53f692a78c
|
@ -39,7 +39,7 @@ from .utils import ensure_is_catalog_bundle
|
|||
from .errors import Error
|
||||
|
||||
|
||||
VERSION = '0.10.1'
|
||||
VERSION = '0.10.2'
|
||||
|
||||
|
||||
__all__ = (
|
||||
|
|
|
@ -13,7 +13,8 @@ GLOBAL_LOCK = threading.RLock()
|
|||
def is_provider(instance):
|
||||
"""Check if instance is provider instance."""
|
||||
return (not isinstance(instance, six.class_types) and
|
||||
getattr(instance, '__IS_PROVIDER__', False) is True)
|
||||
hasattr(instance, '__IS_PROVIDER__') and
|
||||
getattr(instance, '__IS_PROVIDER__') is True)
|
||||
|
||||
|
||||
def ensure_is_provider(instance):
|
||||
|
@ -30,7 +31,8 @@ def ensure_is_provider(instance):
|
|||
def is_injection(instance):
|
||||
"""Check if instance is injection instance."""
|
||||
return (not isinstance(instance, six.class_types) and
|
||||
getattr(instance, '__IS_INJECTION__', False) is True)
|
||||
hasattr(instance, '__IS_INJECTION__') and
|
||||
getattr(instance, '__IS_INJECTION__') is True)
|
||||
|
||||
|
||||
def ensure_is_injection(instance):
|
||||
|
@ -44,36 +46,42 @@ def ensure_is_injection(instance):
|
|||
def is_arg_injection(instance):
|
||||
"""Check if instance is positional argument injection instance."""
|
||||
return (not isinstance(instance, six.class_types) and
|
||||
hasattr(instance, '__IS_ARG_INJECTION__') and
|
||||
getattr(instance, '__IS_ARG_INJECTION__', False) is True)
|
||||
|
||||
|
||||
def is_kwarg_injection(instance):
|
||||
"""Check if instance is keyword argument injection instance."""
|
||||
return (not isinstance(instance, six.class_types) and
|
||||
hasattr(instance, '__IS_KWARG_INJECTION__') and
|
||||
getattr(instance, '__IS_KWARG_INJECTION__', False) is True)
|
||||
|
||||
|
||||
def is_attribute_injection(instance):
|
||||
"""Check if instance is attribute injection instance."""
|
||||
return (not isinstance(instance, six.class_types) and
|
||||
hasattr(instance, '__IS_ATTRIBUTE_INJECTION__') and
|
||||
getattr(instance, '__IS_ATTRIBUTE_INJECTION__', False) is True)
|
||||
|
||||
|
||||
def is_method_injection(instance):
|
||||
"""Check if instance is method injection instance."""
|
||||
return (not isinstance(instance, six.class_types) and
|
||||
hasattr(instance, '__IS_METHOD_INJECTION__') and
|
||||
getattr(instance, '__IS_METHOD_INJECTION__', False) is True)
|
||||
|
||||
|
||||
def is_catalog(instance):
|
||||
"""Check if instance is catalog instance."""
|
||||
return (isinstance(instance, six.class_types) and
|
||||
hasattr(instance, '__IS_CATALOG__') and
|
||||
getattr(instance, '__IS_CATALOG__', False) is True)
|
||||
|
||||
|
||||
def is_catalog_bundle(instance):
|
||||
"""Check if instance is catalog bundle instance."""
|
||||
return (not isinstance(instance, six.class_types) and
|
||||
hasattr(instance, '__IS_CATALOG_BUNDLE__') and
|
||||
getattr(instance, '__IS_CATALOG_BUNDLE__', False) is True)
|
||||
|
||||
|
||||
|
|
|
@ -7,6 +7,10 @@ that were made in every particular version.
|
|||
From version 0.7.6 *Dependency Injector* framework strictly
|
||||
follows `Semantic versioning`_
|
||||
|
||||
0.10.2
|
||||
------
|
||||
- Fix bug with injecting entities that implement ``__getattr__``.
|
||||
|
||||
0.10.1
|
||||
------
|
||||
- Update some examples.
|
||||
|
|
|
@ -16,8 +16,10 @@ app = flask.Flask(__name__)
|
|||
|
||||
@app.route('/')
|
||||
@di.inject(database)
|
||||
def hello(database):
|
||||
@di.inject(flask.request)
|
||||
def hello(request, database):
|
||||
"""Example Flask view."""
|
||||
print request
|
||||
one = database.execute('SELECT 1').fetchone()[0]
|
||||
return 'Query returned {0}, db connection {1}'.format(one, database)
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user