summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Drozd <nicholasdrozd@gmail.com>2023-01-30 12:17:58 -0500
committerDaniƫl van Noord <13665637+DanielNoord@users.noreply.github.com>2023-04-07 09:20:23 +0200
commit5e8c89afe4a12eeab2ab97d95495187990e5df27 (patch)
tree050eb182a028d7f689f6602d7ae9e6014d783843
parent02a622ad3f798c640c541985af5b85ee0233f5fa (diff)
downloadastroid-git-5e8c89afe4a12eeab2ab97d95495187990e5df27.tar.gz
Mandatory fields for TryExcept
-rw-r--r--ChangeLog1
-rw-r--r--astroid/nodes/node_classes.py65
2 files changed, 13 insertions, 53 deletions
diff --git a/ChangeLog b/ChangeLog
index b0ee1155..33eb401c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -38,6 +38,7 @@ Release date: TBA
- ``nodes.Return
- ``nodes.Slice``
- ``nodes.Starred``
+ - ``nodes.TryExcept``
- ``nodes.Subscript``
- ``nodes.UnaryOp``
- ``nodes.While``
diff --git a/astroid/nodes/node_classes.py b/astroid/nodes/node_classes.py
index 5b83d2cb..deb8ed54 100644
--- a/astroid/nodes/node_classes.py
+++ b/astroid/nodes/node_classes.py
@@ -3137,65 +3137,24 @@ class TryExcept(_base_nodes.MultiLineWithElseBlockNode, _base_nodes.Statement):
_astroid_fields = ("body", "handlers", "orelse")
_multi_line_block_fields = ("body", "handlers", "orelse")
- def __init__(
- self,
- lineno: int | None = None,
- col_offset: int | None = None,
- parent: NodeNG | None = None,
- *,
- end_lineno: int | None = None,
- end_col_offset: int | None = None,
- ) -> None:
- """
- :param lineno: The line that this node appears on in the source code.
-
- :param col_offset: The column that this node appears on in the
- source code.
-
- :param parent: The parent node in the syntax tree.
-
- :param end_lineno: The last line this node appears on in the source code.
-
- :param end_col_offset: The end column this node appears on in the
- source code. Note: This is after the last symbol.
- """
- self.body: list[NodeNG] = []
- """The contents of the block to catch exceptions from."""
-
- self.handlers: list[ExceptHandler] = []
- """The exception handlers."""
+ body: list[NodeNG]
+ """The contents of the block to catch exceptions from."""
- self.orelse: list[NodeNG] = []
- """The contents of the ``else`` block."""
+ handlers: list[ExceptHandler]
+ """The exception handlers."""
- super().__init__(
- lineno=lineno,
- col_offset=col_offset,
- end_lineno=end_lineno,
- end_col_offset=end_col_offset,
- parent=parent,
- )
+ orelse: list[NodeNG]
+ """The contents of the ``else`` block."""
def postinit(
self,
- body: list[NodeNG] | None = None,
- handlers: list[ExceptHandler] | None = None,
- orelse: list[NodeNG] | None = None,
+ body: list[NodeNG],
+ handlers: list[ExceptHandler],
+ orelse: list[NodeNG],
) -> None:
- """Do some setup after initialisation.
-
- :param body: The contents of the block to catch exceptions from.
-
- :param handlers: The exception handlers.
-
- :param orelse: The contents of the ``else`` block.
- """
- if body is not None:
- self.body = body
- if handlers is not None:
- self.handlers = handlers
- if orelse is not None:
- self.orelse = orelse
+ self.body = body
+ self.handlers = handlers
+ self.orelse = orelse
def _infer_name(self, frame, name):
return name