<commit_before>from jaspyx.context.block import BlockContext
from jaspyx.scope import Scope


class FunctionContext(BlockContext):
    def __init__(self, parent, name, arg_names=[]):
        super(FunctionContext, self).__init__(parent)
        self.scope = Scope(self.scope)
        self.name = name
        self.arg_names = arg_names
        for arg_name in self.arg_names:
            self.scope.declare(arg_name, False)

    def __str__(self):
        declare_vars = [k for k, v in self.scope.declarations.items() if v]

        if not self.scope.prefix and declare_vars:
            indent = ' ' * (self.indent + 2)
            stmt = '%svar %s;\n' % (indent, ', '.join(declare_vars))
            self.body.insert(0, stmt)

        args = ', '.join(self.arg_names)
        body = super(FunctionContext, self).__str__()
        if self.name:
            return '%s = function(%s) %s' % (
                self.scope.parent.prefixed(self.name),
                args,<commit_msg>Don't create new scope if context doesn't have a parent.<commit_after>from jaspyx.context.block import BlockContext
from jaspyx.scope import Scope


class FunctionContext(BlockContext):
    def __init__(self, parent, name, arg_names=[]):
        super(FunctionContext, self).__init__(parent)
        if parent:
            self.scope = Scope(self.scope)
        self.name = name
        self.arg_names = arg_names
        for arg_name in self.arg_names:
            self.scope.declare(arg_name, False)

    def __str__(self):
        declare_vars = [k for k, v in self.scope.declarations.items() if v]

        if not self.scope.prefix and declare_vars:
            indent = ' ' * (self.indent + 2)
            stmt = '%svar %s;\n' % (indent, ', '.join(declare_vars))
            self.body.insert(0, stmt)

        args = ', '.join(self.arg_names)
        body = super(FunctionContext, self).__str__()
        if self.name:
            return '%s = function(%s) %s' % (
                self.scope.parent.prefixed(self.name),
                args,
{'fraction_non_alphanumeric': 0.12043435340572557, 'fraction_numerical': 0.0019743336623889436, 'mean_word_length': 2.2536115569823436, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4302091', 'n_tokens_mistral': 633, 'n_tokens_neox': 614, 'n_words': 146}