@@ -2741,7 +2741,8 @@ def get_children(self):
2741
2741
yield from ()
2742
2742
2743
2743
2744
- class ExceptHandler (mixins .AssignTypeMixin , Statement ):
2744
+ class ExceptHandler (mixins .MultiLineBlockMixin ,
2745
+ mixins .AssignTypeMixin , Statement ):
2745
2746
"""Class representing an :class:`ast.ExceptHandler`. node.
2746
2747
2747
2748
An :class:`ExceptHandler` is an ``except`` block on a try-except.
@@ -2758,6 +2759,7 @@ class ExceptHandler(mixins.AssignTypeMixin, Statement):
2758
2759
[<ExceptHandler l.4 at 0x7f23b2e9e860>]
2759
2760
"""
2760
2761
_astroid_fields = ('type' , 'name' , 'body' ,)
2762
+ _multi_line_block_fields = ('body' ,)
2761
2763
type = None
2762
2764
"""The types that the block handles.
2763
2765
@@ -2828,18 +2830,6 @@ def catch(self, exceptions): # pylint: disable=redefined-outer-name
2828
2830
return True
2829
2831
return False
2830
2832
2831
- def _get_return_nodes_skip_functions (self ):
2832
- for child_node in self .body :
2833
- if child_node .is_function :
2834
- continue
2835
- yield from child_node ._get_return_nodes_skip_functions ()
2836
-
2837
- def _get_yield_nodes_skip_lambdas (self ):
2838
- for child_node in self .body :
2839
- if child_node .is_lambda :
2840
- continue
2841
- yield from child_node ._get_yield_nodes_skip_lambdas ()
2842
-
2843
2833
2844
2834
class Exec (Statement ):
2845
2835
"""Class representing the ``exec`` statement.
@@ -2910,14 +2900,16 @@ def postinit(self, dims=None):
2910
2900
self .dims = dims
2911
2901
2912
2902
2913
- class For (mixins .BlockRangeMixIn , mixins .AssignTypeMixin , Statement ):
2903
+ class For (mixins .MultiLineBlockMixin , mixins .BlockRangeMixIn ,
2904
+ mixins .AssignTypeMixin , Statement ):
2914
2905
"""Class representing an :class:`ast.For` node.
2915
2906
2916
2907
>>> node = astroid.extract_node('for thing in things: print(thing)')
2917
2908
>>> node
2918
2909
<For l.1 at 0x7f23b2e8cf28>
2919
2910
"""
2920
2911
_astroid_fields = ('target' , 'iter' , 'body' , 'orelse' ,)
2912
+ _multi_line_block_fields = ('body' , 'orelse' )
2921
2913
target = None
2922
2914
"""What the loop assigns to.
2923
2915
@@ -2983,35 +2975,6 @@ def get_children(self):
2983
2975
yield from self .body
2984
2976
yield from self .orelse
2985
2977
2986
- def _get_assign_nodes (self ):
2987
- for child_node in self .body :
2988
- yield from child_node ._get_assign_nodes ()
2989
-
2990
- for child_node in self .orelse :
2991
- yield from child_node ._get_assign_nodes ()
2992
-
2993
- def _get_return_nodes_skip_functions (self ):
2994
- for child_node in self .body :
2995
- if child_node .is_function :
2996
- continue
2997
- yield from child_node ._get_return_nodes_skip_functions ()
2998
-
2999
- for child_node in self .orelse :
3000
- if child_node .is_function :
3001
- continue
3002
- yield from child_node ._get_return_nodes_skip_functions ()
3003
-
3004
- def _get_yield_nodes_skip_lambdas (self ):
3005
- for child_node in self .body :
3006
- if child_node .is_lambda :
3007
- continue
3008
- yield from child_node ._get_yield_nodes_skip_lambdas ()
3009
-
3010
- for child_node in self .orelse :
3011
- if child_node .is_lambda :
3012
- continue
3013
- yield from child_node ._get_yield_nodes_skip_lambdas ()
3014
-
3015
2978
3016
2979
class AsyncFor (For ):
3017
2980
"""Class representing an :class:`ast.AsyncFor` node.
@@ -3214,14 +3177,15 @@ def get_children(self):
3214
3177
yield from ()
3215
3178
3216
3179
3217
- class If (mixins .BlockRangeMixIn , Statement ):
3180
+ class If (mixins .MultiLineBlockMixin , mixins . BlockRangeMixIn , Statement ):
3218
3181
"""Class representing an :class:`ast.If` node.
3219
3182
3220
3183
>>> node = astroid.extract_node('if condition: print(True)')
3221
3184
>>> node
3222
3185
<If l.1 at 0x7f23b2e9dd30>
3223
3186
"""
3224
3187
_astroid_fields = ('test' , 'body' , 'orelse' )
3188
+ _multi_line_block_fields = ('body' , 'orelse' )
3225
3189
test = None
3226
3190
"""The condition that the statement tests.
3227
3191
@@ -3285,35 +3249,6 @@ def get_children(self):
3285
3249
yield from self .body
3286
3250
yield from self .orelse
3287
3251
3288
- def _get_assign_nodes (self ):
3289
- for child_node in self .body :
3290
- yield from child_node ._get_assign_nodes ()
3291
-
3292
- for child_node in self .orelse :
3293
- yield from child_node ._get_assign_nodes ()
3294
-
3295
- def _get_return_nodes_skip_functions (self ):
3296
- for child_node in self .body :
3297
- if child_node .is_function :
3298
- continue
3299
- yield from child_node ._get_return_nodes_skip_functions ()
3300
-
3301
- for child_node in self .orelse :
3302
- if child_node .is_function :
3303
- continue
3304
- yield from child_node ._get_return_nodes_skip_functions ()
3305
-
3306
- def _get_yield_nodes_skip_lambdas (self ):
3307
- for child_node in self .body :
3308
- if child_node .is_lambda :
3309
- continue
3310
- yield from child_node ._get_yield_nodes_skip_lambdas ()
3311
-
3312
- for child_node in self .orelse :
3313
- if child_node .is_lambda :
3314
- continue
3315
- yield from child_node ._get_yield_nodes_skip_lambdas ()
3316
-
3317
3252
3318
3253
class IfExp (NodeNG ):
3319
3254
"""Class representing an :class:`ast.IfExp` node.
@@ -3952,7 +3887,7 @@ def get_children(self):
3952
3887
yield self .slice
3953
3888
3954
3889
3955
- class TryExcept (mixins .BlockRangeMixIn , Statement ):
3890
+ class TryExcept (mixins .MultiLineBlockMixin , mixins . BlockRangeMixIn , Statement ):
3956
3891
"""Class representing an :class:`ast.TryExcept` node.
3957
3892
3958
3893
>>> node = astroid.extract_node('''
@@ -3965,6 +3900,7 @@ class TryExcept(mixins.BlockRangeMixIn, Statement):
3965
3900
<TryExcept l.2 at 0x7f23b2e9d908>
3966
3901
"""
3967
3902
_astroid_fields = ('body' , 'handlers' , 'orelse' ,)
3903
+ _multi_line_block_fields = ('body' , 'orelse' )
3968
3904
body = None
3969
3905
"""The contents of the block to catch exceptions from.
3970
3906
@@ -4026,38 +3962,9 @@ def get_children(self):
4026
3962
yield from self .handlers or ()
4027
3963
yield from self .orelse or ()
4028
3964
4029
- def _get_assign_nodes (self ):
4030
- for child_node in self .body :
4031
- yield from child_node ._get_assign_nodes ()
4032
-
4033
- for child_node in self .orelse :
4034
- yield from child_node ._get_assign_nodes ()
4035
-
4036
- def _get_return_nodes_skip_functions (self ):
4037
- for child_node in self .body :
4038
- if child_node .is_function :
4039
- continue
4040
- yield from child_node ._get_return_nodes_skip_functions ()
4041
-
4042
- for child_node in self .orelse or ():
4043
- if child_node .is_function :
4044
- continue
4045
- for matching in child_node ._get_return_nodes_skip_functions ():
4046
- yield matching
4047
-
4048
- def _get_yield_nodes_skip_lambdas (self ):
4049
- for child_node in self .body :
4050
- if child_node .is_lambda :
4051
- continue
4052
- yield from child_node ._get_yield_nodes_skip_lambdas ()
4053
-
4054
- for child_node in self .orelse :
4055
- if child_node .is_lambda :
4056
- continue
4057
- yield from child_node ._get_yield_nodes_skip_lambdas ()
4058
-
4059
3965
4060
- class TryFinally (mixins .BlockRangeMixIn , Statement ):
3966
+ class TryFinally (mixins .MultiLineBlockMixin ,
3967
+ mixins .BlockRangeMixIn , Statement ):
4061
3968
"""Class representing an :class:`ast.TryFinally` node.
4062
3969
4063
3970
>>> node = astroid.extract_node('''
@@ -4072,6 +3979,7 @@ class TryFinally(mixins.BlockRangeMixIn, Statement):
4072
3979
<TryFinally l.2 at 0x7f23b2e41d68>
4073
3980
"""
4074
3981
_astroid_fields = ('body' , 'finalbody' ,)
3982
+ _multi_line_block_fields = ('body' , 'finalbody' )
4075
3983
body = None
4076
3984
"""The try-except that the finally is attached to.
4077
3985
@@ -4116,36 +4024,6 @@ def get_children(self):
4116
4024
yield from self .body
4117
4025
yield from self .finalbody
4118
4026
4119
- def _get_assign_nodes (self ):
4120
- for child_node in self .body :
4121
- yield from child_node ._get_assign_nodes ()
4122
-
4123
- for child_node in self .finalbody :
4124
- yield from child_node ._get_assign_nodes ()
4125
-
4126
- def _get_return_nodes_skip_functions (self ):
4127
- for child_node in self .body :
4128
- if child_node .is_function :
4129
- continue
4130
- yield from child_node ._get_return_nodes_skip_functions ()
4131
-
4132
- for child_node in self .finalbody :
4133
- if child_node .is_function :
4134
- continue
4135
- for matching in child_node ._get_return_nodes_skip_functions ():
4136
- yield matching
4137
-
4138
- def _get_yield_nodes_skip_lambdas (self ):
4139
- for child_node in self .body :
4140
- if child_node .is_lambda :
4141
- continue
4142
- yield from child_node ._get_yield_nodes_skip_lambdas ()
4143
-
4144
- for child_node in self .finalbody :
4145
- if child_node .is_lambda :
4146
- continue
4147
- yield from child_node ._get_yield_nodes_skip_lambdas ()
4148
-
4149
4027
4150
4028
class Tuple (_BaseContainer ):
4151
4029
"""Class representing an :class:`ast.Tuple` node.
@@ -4268,7 +4146,7 @@ def get_children(self):
4268
4146
yield self .operand
4269
4147
4270
4148
4271
- class While (mixins .BlockRangeMixIn , Statement ):
4149
+ class While (mixins .MultiLineBlockMixin , mixins . BlockRangeMixIn , Statement ):
4272
4150
"""Class representing an :class:`ast.While` node.
4273
4151
4274
4152
>>> node = astroid.extract_node('''
@@ -4279,6 +4157,7 @@ class While(mixins.BlockRangeMixIn, Statement):
4279
4157
<While l.2 at 0x7f23b2e4e390>
4280
4158
"""
4281
4159
_astroid_fields = ('test' , 'body' , 'orelse' ,)
4160
+ _multi_line_block_fields = ('body' , 'orelse' )
4282
4161
test = None
4283
4162
"""The condition that the loop tests.
4284
4163
@@ -4337,38 +4216,9 @@ def get_children(self):
4337
4216
yield from self .body
4338
4217
yield from self .orelse
4339
4218
4340
- def _get_assign_nodes (self ):
4341
- for child_node in self .body :
4342
- yield from child_node ._get_assign_nodes ()
4343
-
4344
- for child_node in self .orelse :
4345
- yield from child_node ._get_assign_nodes ()
4346
4219
4347
- def _get_return_nodes_skip_functions (self ):
4348
- for child_node in self .body :
4349
- if child_node .is_function :
4350
- continue
4351
- yield from child_node ._get_return_nodes_skip_functions ()
4352
-
4353
- for child_node in self .orelse :
4354
- if child_node .is_function :
4355
- continue
4356
- for matching in child_node ._get_return_nodes_skip_functions ():
4357
- yield matching
4358
-
4359
- def _get_yield_nodes_skip_lambdas (self ):
4360
- for child_node in self .body :
4361
- if child_node .is_lambda :
4362
- continue
4363
- yield from child_node ._get_yield_nodes_skip_lambdas ()
4364
-
4365
- for child_node in self .orelse :
4366
- if child_node .is_lambda :
4367
- continue
4368
- yield from child_node ._get_yield_nodes_skip_lambdas ()
4369
-
4370
-
4371
- class With (mixins .BlockRangeMixIn , mixins .AssignTypeMixin , Statement ):
4220
+ class With (mixins .MultiLineBlockMixin , mixins .BlockRangeMixIn ,
4221
+ mixins .AssignTypeMixin , Statement ):
4372
4222
"""Class representing an :class:`ast.With` node.
4373
4223
4374
4224
>>> node = astroid.extract_node('''
@@ -4379,6 +4229,7 @@ class With(mixins.BlockRangeMixIn, mixins.AssignTypeMixin, Statement):
4379
4229
<With l.2 at 0x7f23b2e4e710>
4380
4230
"""
4381
4231
_astroid_fields = ('items' , 'body' )
4232
+ _multi_line_block_fields = ('body' ,)
4382
4233
items = None
4383
4234
"""The pairs of context managers and the names they are assigned to.
4384
4235
@@ -4424,22 +4275,6 @@ def get_children(self):
4424
4275
for elt in self .body :
4425
4276
yield elt
4426
4277
4427
- def _get_assign_nodes (self ):
4428
- for child_node in self .body :
4429
- yield from child_node ._get_assign_nodes ()
4430
-
4431
- def _get_return_nodes_skip_functions (self ):
4432
- for child_node in self .body :
4433
- if child_node .is_function :
4434
- continue
4435
- yield from child_node ._get_return_nodes_skip_functions ()
4436
-
4437
- def _get_yield_nodes_skip_lambdas (self ):
4438
- for child_node in self .body :
4439
- if child_node .is_lambda :
4440
- continue
4441
- yield from child_node ._get_yield_nodes_skip_lambdas ()
4442
-
4443
4278
4444
4279
class AsyncWith (With ):
4445
4280
"""Asynchronous ``with`` built with the ``async`` keyword."""
0 commit comments