| Total Complexity | 6 |
| Total Lines | 35 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | """ |
||
| 2 | PRIVATE MODULE: do not import (from) it directly. |
||
| 3 | |||
| 4 | This module contains the ``ObjectMatcher``class. |
||
| 5 | """ |
||
| 6 | import inspect |
||
| 7 | from jacked._injectable import Injectable |
||
| 8 | from jacked._container import Container |
||
| 9 | from jacked.matchers._base_matcher import BaseMatcher |
||
| 10 | |||
| 11 | |||
| 12 | class ObjectMatcher(BaseMatcher): |
||
| 13 | |||
| 14 | def match( |
||
| 15 | self, |
||
| 16 | hint: object, |
||
| 17 | injectable: Injectable, |
||
| 18 | container: Container): |
||
| 19 | # The hint is a regular type, so we're expecting to inject an instance. |
||
| 20 | if (inspect.isclass(injectable.subject) |
||
| 21 | and issubclass(injectable.subject, hint)): |
||
| 22 | if injectable.singleton: |
||
| 23 | container.set_instance(hint, injectable.subject(), |
||
| 24 | injectable.priority) |
||
| 25 | result = container.get_instance(hint) |
||
| 26 | else: |
||
| 27 | result = injectable.subject() |
||
| 28 | return result |
||
| 29 | |||
| 30 | def _matching_type(self): |
||
| 31 | return object |
||
| 32 | |||
| 33 | def priority(self): |
||
| 34 | return 0 # The lowest priority. |
||
| 35 |