@@ -4216,6 +4216,107 @@ def get_children(self):
4216
4216
yield from self .finalbody
4217
4217
4218
4218
4219
+ class TryStar (_base_nodes .MultiLineWithElseBlockNode , _base_nodes .Statement ):
4220
+ """Class representing an :class:`ast.TryStar` node."""
4221
+
4222
+ _astroid_fields = ("body" , "handlers" , "orelse" , "finalbody" )
4223
+ _multi_line_block_fields = ("body" , "handlers" , "orelse" , "finalbody" )
4224
+
4225
+ def __init__ (
4226
+ self ,
4227
+ * ,
4228
+ lineno : int | None = None ,
4229
+ col_offset : int | None = None ,
4230
+ end_lineno : int | None = None ,
4231
+ end_col_offset : int | None = None ,
4232
+ parent : NodeNG | None = None ,
4233
+ ) -> None :
4234
+ """
4235
+ :param lineno: The line that this node appears on in the source code.
4236
+ :param col_offset: The column that this node appears on in the
4237
+ source code.
4238
+ :param parent: The parent node in the syntax tree.
4239
+ :param end_lineno: The last line this node appears on in the source code.
4240
+ :param end_col_offset: The end column this node appears on in the
4241
+ source code. Note: This is after the last symbol.
4242
+ """
4243
+ self .body : list [NodeNG ] = []
4244
+ """The contents of the block to catch exceptions from."""
4245
+
4246
+ self .handlers : list [ExceptHandler ] = []
4247
+ """The exception handlers."""
4248
+
4249
+ self .orelse : list [NodeNG ] = []
4250
+ """The contents of the ``else`` block."""
4251
+
4252
+ self .finalbody : list [NodeNG ] = []
4253
+ """The contents of the ``finally`` block."""
4254
+
4255
+ super ().__init__ (
4256
+ lineno = lineno ,
4257
+ col_offset = col_offset ,
4258
+ end_lineno = end_lineno ,
4259
+ end_col_offset = end_col_offset ,
4260
+ parent = parent ,
4261
+ )
4262
+
4263
+ def postinit (
4264
+ self ,
4265
+ * ,
4266
+ body : list [NodeNG ] | None = None ,
4267
+ handlers : list [ExceptHandler ] | None = None ,
4268
+ orelse : list [NodeNG ] | None = None ,
4269
+ finalbody : list [NodeNG ] | None = None ,
4270
+ ) -> None :
4271
+ """Do some setup after initialisation.
4272
+ :param body: The contents of the block to catch exceptions from.
4273
+ :param handlers: The exception handlers.
4274
+ :param orelse: The contents of the ``else`` block.
4275
+ :param finalbody: The contents of the ``finally`` block.
4276
+ """
4277
+ if body :
4278
+ self .body = body
4279
+ if handlers :
4280
+ self .handlers = handlers
4281
+ if orelse :
4282
+ self .orelse = orelse
4283
+ if finalbody :
4284
+ self .finalbody = finalbody
4285
+
4286
+ def _infer_name (self , frame , name ):
4287
+ return name
4288
+
4289
+ def block_range (self , lineno : int ) -> tuple [int , int ]:
4290
+ """Get a range from a given line number to where this node ends."""
4291
+ if lineno == self .fromlineno :
4292
+ return lineno , lineno
4293
+ if self .body and self .body [0 ].fromlineno <= lineno <= self .body [- 1 ].tolineno :
4294
+ # Inside try body - return from lineno till end of try body
4295
+ return lineno , self .body [- 1 ].tolineno
4296
+ for exhandler in self .handlers :
4297
+ if exhandler .type and lineno == exhandler .type .fromlineno :
4298
+ return lineno , lineno
4299
+ if exhandler .body [0 ].fromlineno <= lineno <= exhandler .body [- 1 ].tolineno :
4300
+ return lineno , exhandler .body [- 1 ].tolineno
4301
+ if self .orelse :
4302
+ if self .orelse [0 ].fromlineno - 1 == lineno :
4303
+ return lineno , lineno
4304
+ if self .orelse [0 ].fromlineno <= lineno <= self .orelse [- 1 ].tolineno :
4305
+ return lineno , self .orelse [- 1 ].tolineno
4306
+ if self .finalbody :
4307
+ if self .finalbody [0 ].fromlineno - 1 == lineno :
4308
+ return lineno , lineno
4309
+ if self .finalbody [0 ].fromlineno <= lineno <= self .finalbody [- 1 ].tolineno :
4310
+ return lineno , self .finalbody [- 1 ].tolineno
4311
+ return lineno , self .tolineno
4312
+
4313
+ def get_children (self ):
4314
+ yield from self .body
4315
+ yield from self .handlers
4316
+ yield from self .orelse
4317
+ yield from self .finalbody
4318
+
4319
+
4219
4320
class Tuple (BaseContainer ):
4220
4321
"""Class representing an :class:`ast.Tuple` node.
4221
4322
0 commit comments