jacked._exceptions.InjectionError.__init__()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 9
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nop 3
dl 0
loc 9
rs 10
c 0
b 0
f 0
1
"""
2
PRIVATE MODULE: do not import (from) it directly.
3
4
This module contains the ``jacked`` error classes.
5
"""
6
import inspect
7
from typing import Union
8
9
10
class JackedError(Exception):
11
    """
12
    Base class for all ``jacked`` errors.
13
    """
14
15
16
class InvalidUsageError(JackedError):
17
    """
18
    Raised when ``jacked`` was used in the wrong manner (e.g. decorating a
19
    class with ``@inject``).
20
    """
21
22
23
class InjectionError(JackedError):
24
    """
25
    Raised when injection failed.
26
    """
27
    def __init__(self, msg: str, subject: Union[inspect.Parameter, type]):
28
        """
29
        Constructor.
30
        :param msg: the message of the error.
31
        :param subject: a parameter in case of a decorator injection, a type in
32
        case of ``inject_here`` was used.
33
        """
34
        super(InjectionError, self).__init__(msg)
35
        self.subject = subject
36