| Total Complexity | 2 |
| Total Lines | 39 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 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 |