1#!/usr/bin/env python3
2"""
3
4"""
5
6# Imports:
7from __future__ import annotations
8
9# ##-- stdlib imports
10import atexit# for @atexit.register
11import collections
12import contextlib
13import datetime
14import enum
15import faulthandler
16import functools as ftz
17import hashlib
18import itertools as itz
19import logging as logmod
20import pathlib as pl
21import re
22import time
23import types as types_
24import weakref
25from copy import deepcopy
26from time import sleep
27from uuid import UUID, uuid1
28from weakref import ref
29
30# ##-- end stdlib imports
31
32
33# ##-- types
34# isort: off
35import abc
36import collections.abc
37from typing import TYPE_CHECKING, cast, assert_type, assert_never
38from typing import Generic, NewType
39# Protocols:
40from typing import Protocol, runtime_checkable
41# Typing Decorators:
42from typing import no_type_check, final, override, overload
43
44if TYPE_CHECKING:
45 from .._interface import TomlTypes
46 from jgdv import Maybe
47 from typing import Final
48 from typing import ClassVar, Any, LiteralString
49 from typing import Never, Self, Literal
50 from typing import TypeGuard
51 from collections.abc import Iterable, Iterator, Callable, Generator
52 from collections.abc import Sequence, Mapping, MutableMapping, Hashable
53
54##--|
55
56# isort: on
57# ##-- end types
58
59##-- logging
60logging = logmod.getLogger(__name__)
61##-- end logging
62
[docs]
63class DefaultedReporter_m:
64 """ A Mixin for reporting values that a failure proxy defaulted on. """
65
66 _defaulted : ClassVar[set[str]] = set()
67
[docs]
68 @staticmethod
69 def add_defaulted(index:str|list[str], val:Any, types:Maybe[str]=None) -> None: # noqa: ANN401
70 index_str : str
71 ##--|
72 types = types or "Any"
73 match index, val:
74 case _, ():
75 return
76 case list(), _:
77 msg = "Tried to Register a default value with a list index, use a str"
78 raise TypeError(msg)
79 case str(), bool():
80 index_str = f"{index} = {str(val).lower()} # <{types}>"
81 case str(), _:
82 index_str = f"{index} = {val!r} # <{types}>"
83 case [*xs], bool():
84 index_path = ".".join(xs)
85 index_str = f"{index_path} = {str(val).lower()} # <{types}>"
86 case [*xs], _:
87 index_path = ".".join(xs)
88 index_str = f"{index_path} = {val} # <{types}>"
89 case _, _:
90 msg = "Unexpected Values found: "
91 raise TypeError(msg, val, index)
92
93 DefaultedReporter_m._defaulted.add(index_str)
94
[docs]
95 @staticmethod
96 def report_defaulted() -> list[str]:
97 """
98 Report the index paths inject default values
99 """
100 return list(DefaultedReporter_m._defaulted)