| Total Complexity | 4 |
| Total Lines | 53 |
| Duplicated Lines | 0 % |
| Coverage | 95% |
| Changes | 0 | ||
| 1 | """ |
||
| 2 | Exceptions raised by the library |
||
| 3 | """ |
||
| 4 | 1 | from abc import ABC |
|
| 5 | 1 | from typing import Type |
|
| 6 | |||
| 7 | 1 | import typing |
|
| 8 | |||
| 9 | |||
| 10 | 1 | class LagomException(Exception, ABC): |
|
| 11 | """All exceptions in this library are instances of a LagomException""" |
||
| 12 | |||
| 13 | 1 | pass |
|
| 14 | |||
| 15 | |||
| 16 | 1 | class InvalidDependencyDefinition(ValueError, LagomException): |
|
| 17 | """The provided construction logic is not valid""" |
||
| 18 | |||
| 19 | 1 | pass |
|
| 20 | |||
| 21 | |||
| 22 | 1 | class MissingReturnType(SyntaxError, LagomException): |
|
| 23 | """The function provided doesnt type hint a return""" |
||
| 24 | |||
| 25 | 1 | pass |
|
| 26 | |||
| 27 | |||
| 28 | 1 | class DuplicateDefinition(ValueError, LagomException): |
|
| 29 | """The type has already been defined somewhere else""" |
||
| 30 | |||
| 31 | 1 | pass |
|
| 32 | |||
| 33 | |||
| 34 | 1 | class UnresolvableType(ValueError, LagomException): |
|
| 35 | """The type cannot be constructed""" |
||
| 36 | |||
| 37 | 1 | dep_type: str |
|
| 38 | |||
| 39 | 1 | def __init__(self, dep_type: Type): |
|
| 40 | """ |
||
| 41 | |||
| 42 | :param dep_type: The type that could not be constructed |
||
| 43 | """ |
||
| 44 | # This first check makes 3.6 behave the same as 3.7 and later |
||
| 45 | 1 | if hasattr(typing, "GenericMeta") and isinstance(dep_type, typing.GenericMeta): |
|
| 46 | self.dep_type = str(dep_type) |
||
| 47 | 1 | elif hasattr(dep_type, "__name__"): |
|
| 48 | 1 | self.dep_type = dep_type.__name__ |
|
| 49 | else: |
||
| 50 | 1 | self.dep_type = str(dep_type) |
|
| 51 | 1 | super().__init__( |
|
| 52 | f"Unable to construct dependency of type {self.dep_type} " |
||
| 53 | "The constructor probably has some unresolvable dependencies" |
||
| 55 |