Total Complexity | 4 |
Total Lines | 38 |
Duplicated Lines | 34.21 % |
Changes | 0 |
Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | from typing import Any, Type |
||
2 | |||
3 | import numpy |
||
4 | from typish import get_mro |
||
5 | |||
6 | from nptyping.types._nptype import NPType |
||
7 | |||
8 | |||
9 | View Code Duplication | class _BoolMeta(type): |
|
|
|||
10 | def __repr__(cls): |
||
11 | return 'Bool' |
||
12 | |||
13 | __str__ = __repr__ |
||
14 | |||
15 | def __instancecheck__(cls, instance: Any) -> bool: |
||
16 | from nptyping.functions._get_type import get_type |
||
17 | np_type = get_type(instance) |
||
18 | return np_type == Bool and issubclass(np_type, cls) |
||
19 | |||
20 | def __subclasscheck__(cls, subclass: type) -> bool: |
||
21 | return Bool in get_mro(subclass) |
||
22 | |||
23 | |||
24 | class Bool(NPType, numpy.bool_, metaclass=_BoolMeta): |
||
25 | """ |
||
26 | Corresponds to numpy.bool_. |
||
27 | """ |
||
28 | |||
29 | @classmethod |
||
30 | def type_of(cls, obj: Any) -> Type['Bool']: |
||
31 | """ |
||
32 | Return the NPType that corresponds to obj. |
||
33 | :param obj: a string compatible object. |
||
34 | :return: a Unicode type. |
||
35 | """ |
||
36 | from nptyping.functions._get_type import get_type_bool |
||
37 | return get_type_bool(obj) |
||
38 |