Completed
Pull Request — master (#23)
by Ramon
01:34
created

jsons.classes.verbosity   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 18
dl 0
loc 30
rs 10
c 0
b 0
f 0

1 Method

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