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
| 61 | |
| 62 | |
| 63 | class TOMLDecodeError(ValueError): |
| 64 | """An error raised if a document is not valid TOML. |
| 65 | |
| 66 | Adds the following attributes to ValueError: |
| 67 | msg: The unformatted error message |
| 68 | doc: The TOML document being parsed |
| 69 | pos: The index of doc where parsing failed |
| 70 | lineno: The line corresponding to pos |
| 71 | colno: The column corresponding to pos |
| 72 | """ |
| 73 | |
| 74 | def __init__( |
| 75 | self, |
| 76 | msg: str = DEPRECATED_DEFAULT, # type: ignore[assignment] |
| 77 | doc: str = DEPRECATED_DEFAULT, # type: ignore[assignment] |
| 78 | pos: Pos = DEPRECATED_DEFAULT, # type: ignore[assignment] |
| 79 | *args: Any, |
| 80 | ): |
| 81 | if ( |
| 82 | args |
| 83 | or not isinstance(msg, str) |
| 84 | or not isinstance(doc, str) |
| 85 | or not isinstance(pos, int) |
| 86 | ): |
| 87 | import warnings |
| 88 | |
| 89 | warnings.warn( |
| 90 | "Free-form arguments for TOMLDecodeError are deprecated. " |
| 91 | "Please set 'msg' (str), 'doc' (str) and 'pos' (int) arguments only.", |
| 92 | DeprecationWarning, |
| 93 | stacklevel=2, |
| 94 | ) |
| 95 | if pos is not DEPRECATED_DEFAULT: # type: ignore[comparison-overlap] |
| 96 | args = pos, *args |
| 97 | if doc is not DEPRECATED_DEFAULT: # type: ignore[comparison-overlap] |
| 98 | args = doc, *args |
| 99 | if msg is not DEPRECATED_DEFAULT: # type: ignore[comparison-overlap] |
| 100 | args = msg, *args |
| 101 | ValueError.__init__(self, *args) |
| 102 | return |
| 103 | |
| 104 | lineno = doc.count("\n", 0, pos) + 1 |
| 105 | if lineno == 1: |
| 106 | colno = pos + 1 |
| 107 | else: |
| 108 | colno = pos - doc.rindex("\n", 0, pos) |
| 109 | |
| 110 | if pos >= len(doc): |
| 111 | coord_repr = "end of document" |
| 112 | else: |
| 113 | coord_repr = f"line {lineno}, column {colno}" |
| 114 | errmsg = f"{msg} (at {coord_repr})" |
| 115 | ValueError.__init__(self, errmsg) |
| 116 | |
| 117 | self.msg = msg |
| 118 | self.doc = doc |
| 119 | self.pos = pos |
| 120 | self.lineno = lineno |
no outgoing calls
no test coverage detected