jacked.matchers._object   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 23
dl 0
loc 35
rs 10
c 0
b 0
f 0
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A ObjectMatcher.priority() 0 2 1
A ObjectMatcher._matching_type() 0 2 1
A ObjectMatcher.match() 0 15 4
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