Skip to content

Default argument naming a local gets EvalLocalVar in a nested @pyscript_compile/@pyscript_executor function #945

Backlog

Description

@craigbarratt

A @pyscript_compile or @pyscript_executor function defined inside a pyscript function gets pyscript's internal EvalLocalVar cell instead of the value when a default argument names a local variable:

def outer():
    i = 3

    @pyscript_compile
    def inner(x=i):
        return x * 10

    return inner()

outer()
# TypeError: unsupported operand type(s) for *: 'EvalLocalVar' and 'int'
# Python: 30

The function is compiled with exec() using the enclosing function's symbol table, where locals are kept in EvalLocalVar cells, so the default is evaluated to the cell itself. This is the same on 2.1.1 and 3.0.0. Found while reviewing #942.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions