Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _insertInitialSetLocalsDictStatement(function_body, function_statements_body):
locals_statement = StatementSetLocalsDictionary(
locals_scope=function_body.getFunctionLocalsScope(),
source_ref=function_body.source_ref,
)
if function_statements_body is None:
function_statements_body = makeStatementsSequenceFromStatement(
statement=locals_statement
)
else:
function_statements_body.setStatements(
(locals_statement,) + function_statements_body.getStatements()
)
return function_statements_body
result = makeInternalHelperFunctionBody(
name=helper_name,
parameters=ParameterSpec(
ps_name=helper_name,
ps_normal_args=("called",),
ps_list_star_arg=None,
ps_dict_star_arg=None,
ps_default_count=0,
ps_kw_only_args=(),
),
)
called_variable = result.getVariableForAssignment(variable_name="called")
functions_case = makeStatementsSequenceFromStatement(
statement=(
StatementReturn(
expression=makeBinaryOperationNode(
operator="Add",
right=makeConstantRefNode(
constant="()",
source_ref=internal_source_ref,
user_provided=True,
),
left=_makeNameAttributeLookup(
ExpressionVariableRef(
variable=called_variable, source_ref=internal_source_ref
)
),
source_ref=internal_source_ref,
),
def _insertFinalReturnStatement(function_statements_body, return_statement):
if function_statements_body is None:
function_statements_body = makeStatementsSequenceFromStatement(
statement=return_statement
)
elif not function_statements_body.isStatementAborting():
function_statements_body.setStatements(
function_statements_body.getStatements() + (return_statement,)
)
return function_statements_body
final = (
StatementReleaseVariable(
variable=called_variable, source_ref=internal_source_ref
),
StatementReleaseVariable(
variable=args_variable, source_ref=internal_source_ref
),
StatementReleaseVariable(variable=kw_variable, source_ref=internal_source_ref),
StatementReleaseVariable(
variable=star_arg_list_variable, source_ref=internal_source_ref
),
)
result.setBody(
makeStatementsSequenceFromStatement(
makeTryFinallyStatement(
provider=result,
tried=statements,
final=final,
source_ref=internal_source_ref,
)
)
)
return result
StatementReturn(
expression=_makeComparisonNode(
left=left,
right=right,
comparator=comparator,
source_ref=source_ref,
),
source_ref=source_ref,
)
)
final.append(
StatementReleaseVariable(variable=tmp_variable, source_ref=source_ref)
)
outline_body.setBody(
makeStatementsSequenceFromStatement(
statement=makeTryFinallyStatement(
provider=outline_body,
tried=statements,
final=final,
source_ref=source_ref,
)
)
)
return outline_body
StatementAssignmentVariable(
variable=tmp_result_variable,
source=makeConstantRefNode(constant={}, source_ref=internal_source_ref),
source_ref=internal_source_ref,
),
StatementLoop(body=loop_body, source_ref=internal_source_ref),
StatementReturn(
expression=ExpressionTempVariableRef(
variable=tmp_result_variable, source_ref=internal_source_ref
),
source_ref=internal_source_ref,
),
)
result.setBody(
makeStatementsSequenceFromStatement(
makeTryFinallyStatement(
provider=result,
tried=tried,
final=final,
source_ref=internal_source_ref,
)
)
)
return result
if function_kind == "Function":
code_body = function_body
else:
code_body = ExpressionGeneratorObjectBody(
provider=function_body,
name="",
code_object=code_object,
flags=set(),
source_ref=source_ref,
)
code_body.qualname_provider = provider
if function_kind == "Generator":
function_body.setBody(
makeStatementsSequenceFromStatement(
statement=StatementReturn(
expression=ExpressionMakeGeneratorObject(
generator_ref=ExpressionFunctionRef(
function_body=code_body, source_ref=source_ref
),
source_ref=source_ref,
),
source_ref=source_ref,
)
)
)
defaults = buildNodeList(provider, node.args.defaults, source_ref)
kw_defaults = buildParameterKwDefaults(
provider=provider, node=node, function_body=function_body, source_ref=source_ref
)
builtin_name="classobj", source_ref=internal_source_ref
),
source_ref=internal_source_ref,
),
yes_branch=class_case,
no_branch=no_branch,
source_ref=internal_source_ref,
)
if python_version < 300:
normal_cases = ("function", "builtin_function_or_method", "instancemethod")
else:
normal_cases = ("function", "builtin_function_or_method")
result.setBody(
makeStatementsSequenceFromStatement(
statement=makeStatementConditional(
condition=ExpressionBuiltinIsinstance(
instance=ExpressionVariableRef(
variable=called_variable, source_ref=internal_source_ref
),
classes=ExpressionMakeTuple(
elements=tuple(
ExpressionBuiltinAnonymousRef(
builtin_name=builtin_name,
source_ref=internal_source_ref,
)
for builtin_name in normal_cases
),
source_ref=internal_source_ref,
),
source_ref=internal_source_ref,
releases.append(
StatementReleaseVariable(variable=variable, source_ref=source_ref)
)
if releases:
body = function.getBody()
if body.isStatementsFrame():
body = makeStatementsSequenceFromStatement(statement=body)
body = makeTryFinallyStatement(
provider=function, tried=body, final=releases, source_ref=source_ref
)
function.setBody(makeStatementsSequenceFromStatement(statement=body))
)
else:
tried = None
if type(final) in (tuple, list):
if final:
final = StatementsSequence(
statements = mergeStatements(final, False),
source_ref = source_ref
)
else:
final = None
if tried is not None and not tried.isStatementsSequence():
tried = makeStatementsSequenceFromStatement(tried)
if final is not None and not final.isStatementsSequence():
final = makeStatementsSequenceFromStatement(final)
# Trivial case, nothing tried needs only do the final stuff.
if tried is None:
return final
# Trivial case, nothing final needs nothing but the tried stuff.
if final is None:
return tried
# Parent them to us already.
if provider is not None:
tried.parent = provider
final.parent = provider
# TODO: Currently it's not possible anymore to get at XML for all codes
# during the building phase. So this error catcher cannot work currently.