MCPcopy Index your code
hub / github.com/python/cpython / __init__

Method __init__

Lib/tomllib/_parser.py:75–122  ·  view source on GitHub ↗
(
        self,
        msg: str = DEPRECATED_DEFAULT,  # type: ignore[assignment]
        doc: str = DEPRECATED_DEFAULT,  # type: ignore[assignment]
        pos: Pos = DEPRECATED_DEFAULT,  # type: ignore[assignment]
        *args: Any,
    )

Source from the content-addressed store, hash-verified

73 """
74
75 def __init__(
76 self,
77 msg: str = DEPRECATED_DEFAULT, # type: ignore[assignment]
78 doc: str = DEPRECATED_DEFAULT, # type: ignore[assignment]
79 pos: Pos = DEPRECATED_DEFAULT, # type: ignore[assignment]
80 *args: Any,
81 ):
82 if (
83 args
84 or not isinstance(msg, str)
85 or not isinstance(doc, str)
86 or not isinstance(pos, int)
87 ):
88 import warnings
89
90 warnings.warn(
91 "Free-form arguments for TOMLDecodeError are deprecated. "
92 "Please set 'msg' (str), 'doc' (str) and 'pos' (int) arguments only.",
93 DeprecationWarning,
94 stacklevel=2,
95 )
96 if pos is not DEPRECATED_DEFAULT: # type: ignore[comparison-overlap]
97 args = pos, *args
98 if doc is not DEPRECATED_DEFAULT: # type: ignore[comparison-overlap]
99 args = doc, *args
100 if msg is not DEPRECATED_DEFAULT: # type: ignore[comparison-overlap]
101 args = msg, *args
102 ValueError.__init__(self, *args)
103 return
104
105 lineno = doc.count("\n", 0, pos) + 1
106 if lineno == 1:
107 colno = pos + 1
108 else:
109 colno = pos - doc.rindex("\n", 0, pos)
110
111 if pos >= len(doc):
112 coord_repr = "end of document"
113 else:
114 coord_repr = f"line {lineno}, column {colno}"
115 errmsg = f"{msg} (at {coord_repr})"
116 ValueError.__init__(self, errmsg)
117
118 self.msg = msg
119 self.doc = doc
120 self.pos = pos
121 self.lineno = lineno
122 self.colno = colno
123
124
125def load(fp: IO[bytes], /, *, parse_float: ParseFloat = float) -> dict[str, Any]:

Callers

nothing calls this directly

Calls 4

warnMethod · 0.45
__init__Method · 0.45
countMethod · 0.45
rindexMethod · 0.45

Tested by

no test coverage detected