| 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 _Datetime64Meta(type): |
|
|
|
|||
| 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 |
||
| 17 | np_type = get_type(instance) |
||
| 18 | return np_type == Datetime64 and issubclass(np_type, 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 |