Skip to content

Commit

Permalink
Improve the SyntaxError constructor; add `SyntaxError.print_file_an…
Browse files Browse the repository at this point in the history
…d_line` (#13141)
  • Loading branch information
tungol authored Nov 27, 2024
1 parent 696e631 commit 11ec1a1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
1 change: 0 additions & 1 deletion stdlib/@tests/stubtest_allowlists/common.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ xml.sax.expatreader
_thread.RLock
_threading_local._localimpl.localargs
_threading_local._localimpl.locallock
builtins.SyntaxError.print_file_and_line
bz2.BZ2File.peek
codecs.StreamReader.charbuffertype
codecs.StreamReader.seek
Expand Down
21 changes: 20 additions & 1 deletion stdlib/builtins.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -1963,14 +1963,33 @@ class StopAsyncIteration(Exception):

class SyntaxError(Exception):
msg: str
filename: str | None
lineno: int | None
offset: int | None
text: str | None
filename: str | None
# Errors are displayed differently if this attribute exists on the exception.
# The value is always None.
print_file_and_line: None
if sys.version_info >= (3, 10):
end_lineno: int | None
end_offset: int | None

@overload
def __init__(self) -> None: ...
@overload
def __init__(self, msg: object, /) -> None: ...
# Second argument is the tuple (filename, lineno, offset, text)
@overload
def __init__(self, msg: str, info: tuple[str | None, int | None, int | None, str | None], /) -> None: ...
if sys.version_info >= (3, 10):
# end_lineno and end_offset must both be provided if one is.
@overload
def __init__(
self, msg: str, info: tuple[str | None, int | None, int | None, str | None, int | None, int | None], /
) -> None: ...
# If you provide more than two arguments, it still creates the SyntaxError, but
# the arguments from the info tuple are not parsed. This form is omitted.

class SystemError(Exception): ...
class TypeError(Exception): ...
class ValueError(Exception): ...
Expand Down

0 comments on commit 11ec1a1

Please sign in to comment.