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