Closed MartinThoma closed 3 years ago
astpretty --no-show-offsets /dev/stdin <<< `cat example.txt`
Module(
body=[
FunctionDef(
name='foo',
args=arguments(posonlyargs=[], args=[], vararg=None, kwonlyargs=[], kw_defaults=[], kwarg=None, defaults=[]),
body=[
Try(
body=[
Expr(
value=BinOp(
left=Constant(value=1, kind=None),
op=Div(),
right=Constant(value=0, kind=None),
),
),
Return(
value=Constant(value='1', kind=None),
),
],
handlers=[
ExceptHandler(
type=None,
name=None,
body=[
Return(
value=Constant(value='2', kind=None),
),
],
),
],
orelse=[],
finalbody=[
Return(
value=Constant(value='3', kind=None),
),
],
),
],
decorator_list=[],
returns=None,
type_comment=None,
),
],
type_ignores=[],
)
Explanation
The return value might be unexpected in a try-except-finally clause. It is better to avoid a return in those cases
Example