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

jsons._extra_impl   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 15
dl 0
loc 39
rs 10
c 0
b 0
f 0

2 Functions

Rating   Name   Duplication   Size   Complexity  
A suppress_warnings() 0 10 1
A announce_class() 0 16 1
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