jsons.classes.verbosity   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 21
dl 0
loc 33
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A Verbosity.from_value() 0 16 5
1
try:
2
    from enum import Flag
3
except ImportError:  # pragma: no cover
4
    from jsons._compatibility_impl import Flag
5
6
7
class Verbosity(Flag):
8
    """
9
    An enum that defines the level of verbosity of the serialization of an
10
    object.
11
    """
12
    WITH_NOTHING = 0
13
    WITH_CLASS_INFO = 10
14
    WITH_DUMP_TIME = 20
15
    WITH_EVERYTHING = WITH_CLASS_INFO | WITH_DUMP_TIME
16
17
    @staticmethod
18
    def from_value(value: any) -> 'Verbosity':
19
        """
20
        Return a ``Verbosity`` instance from the given value.
21
        :param value:
22
        :return: a ``Verbosity`` instance corresponding to ``value``.
23
        """
24
        if isinstance(value, Verbosity):
25
            return value
26
        if value in (False, None):
27
            return Verbosity.WITH_NOTHING
28
        if value is True:
29
            return Verbosity.WITH_EVERYTHING
30
        if value:
31
            return Verbosity.WITH_EVERYTHING
32
        return Verbosity.WITH_NOTHING
33