An error raised if a document is not valid TOML. Adds the following attributes to ValueError: msg: The unformatted error message doc: The TOML document being parsed pos: The index of doc where parsing failed lineno: The line corresponding to pos colno: The column correspondi
| 62 | |
| 63 | |
| 64 | class TOMLDecodeError(ValueError): |
| 65 | """An error raised if a document is not valid TOML. |
| 66 | |
| 67 | Adds the following attributes to ValueError: |
| 68 | msg: The unformatted error message |
| 69 | doc: The TOML document being parsed |
| 70 | pos: The index of doc where parsing failed |
| 71 | lineno: The line corresponding to pos |
| 72 | colno: The column corresponding to pos |
| 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 |
no outgoing calls
no test coverage detected
searching dependent graphs…