Skip to content

Commit

Permalink
Deprecate install_into
Browse files Browse the repository at this point in the history
I see no legitimate use case for it. Injecting into non-constructor
methods would be one but support for that has been removed.
  • Loading branch information
jstasiak committed Jan 12, 2018
1 parent 62e831c commit d6786a7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Injector Change Log

- Deprecated with_injector. There's no one migration path recommended, it depends on
a particular case.
- Deprecated install_into.

0.13.3
------
Expand Down
13 changes: 10 additions & 3 deletions injector.py
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ def create_object(self, cls, additional_kwargs=None):
(), {}, e, self._stack,),
maximum_frames=2)
try:
self.install_into(instance)
self.install_into(instance, _internal = True)
installed = True
except AttributeError:
installed = False
Expand All @@ -776,7 +776,7 @@ def create_object(self, cls, additional_kwargs=None):
if installed:
self._uninstall_from(instance)

def install_into(self, instance):
def install_into(self, instance, *, _internal = False):
"""Put injector reference in given object.
This method has, in general, two applications:
Expand Down Expand Up @@ -814,6 +814,13 @@ def run(self, s: str):
behaviour of that object immediately or in the future.
"""
if not _internal:
warnings.warn(
'install_into is deprecated and will be removed in the next minor release. '
'There should be no reason to use it anymore apart from some very custom cases.',
RuntimeWarning,
stacklevel=3,
)
instance.__injector__ = self

def _uninstall_from(self, instance):
Expand Down Expand Up @@ -956,7 +963,7 @@ def wrapper(f):
@functools.wraps(f)
def setup(self_, *args, **kwargs):
injector = Injector(*injector_args, **injector_kwargs)
injector.install_into(self_)
injector.install_into(self_, _internal = True)
return f(self_, *args, **kwargs)

return setup
Expand Down

0 comments on commit d6786a7

Please sign in to comment.