Completed
Push — master ( 7be5b2...0ef053 )
by Ramon
24s queued 10s
created

jsons._extra_impl.announce_class()   A

Complexity

Conditions 1

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 16
rs 10
c 0
b 0
f 0
cc 1
nop 3
1
"""
2
PRIVATE MODULE: do not import (from) it directly.
3
4
This module contains implementations that do not directly touch the core of
5
jsons.
6
"""
7
from typing import Optional
8
from jsons._common_impl import StateHolder, get_class_name
9
10
11
def suppress_warnings(
12
        do_suppress: Optional[bool] = True,
13
        fork_inst: Optional[type] = StateHolder):
14
    """
15
    Suppress (or stop suppressing) warnings.
16
    :param do_suppress: if ``True``, warnings will be suppressed from now on.
17
    :param fork_inst: if given, it uses this fork of ``JsonSerializable``.
18
    :return: None.
19
    """
20
    fork_inst._suppress_warnings = do_suppress
21
22
23
def announce_class(
24
        cls: type,
25
        cls_name: Optional[str] = None,
26
        fork_inst: type = StateHolder):
27
    """
28
    Announce the given cls to jsons to allow jsons to deserialize a verbose
29
    dump into that class.
30
    :param cls: the class that is to be announced.
31
    :param cls_name: a custom name for that class.
32
    :param fork_inst: if given, it uses this fork of ``JsonSerializable``.
33
    :return: None.
34
    """
35
    cls_name = cls_name or get_class_name(cls, fully_qualified=True,
36
                                          fork_inst=fork_inst)
37
    fork_inst._announced_classes[cls] = cls_name
38
    fork_inst._announced_classes[cls_name] = cls
39