Completed
Push — master ( c5214c...748306 )
by Ramon
23s queued 12s
created

_Datetime64Meta.__instancecheck__()   A

Complexity

Conditions 1

Size

Total Lines 4
Code Lines 4

Duplication

Lines 4
Ratio 100 %

Importance

Changes 0
Metric Value
eloc 4
dl 4
loc 4
rs 10
c 0
b 0
f 0
cc 1
nop 2
1
from typing import Type, Any
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 _Datetime64Meta(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 'Datetime64'
12
13
    __str__ = __repr__
14
15
    def __instancecheck__(cls, instance: Any) -> bool:
16
        from nptyping.functions._get_type import get_type_datetime64
17
        datetime_ = get_type_datetime64(instance)
18
        return issubclass(datetime_, cls)
19
20
    def __subclasscheck__(cls, subclass: type) -> bool:
21
        return Datetime64 in get_mro(subclass)
22
23
24
class Datetime64(NPType, numpy.datetime64, metaclass=_Datetime64Meta):
25
    """
26
    Corresponds to numpy.datetime64.
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 Datetime64 type.
35
        """
36
        from nptyping.functions._get_type import get_type_datetime64
37
        return get_type_datetime64(obj)
38