nptyping.types._bool   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 34.21 %

Importance

Changes 0
Metric Value
wmc 4
eloc 20
dl 13
loc 38
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A _BoolMeta.__repr__() 2 2 1
A _BoolMeta.__subclasscheck__() 2 2 1
A Bool.type_of() 0 9 1
A _BoolMeta.__instancecheck__() 4 4 1

How to fix   Duplicated Code   

Duplicated Code

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):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
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