Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python interpreter frame scope creation bug? #292

Open
timmwagener opened this issue Sep 11, 2021 · 0 comments
Open

Python interpreter frame scope creation bug? #292

timmwagener opened this issue Sep 11, 2021 · 0 comments

Comments

@timmwagener
Copy link

timmwagener commented Sep 11, 2021

As i am following the (rewarding) book i have come across a part in the Python Interpreter chapter for which i am having trouble following the logic. Specifically it is about make_frame() in the Virtualmachine class in this line.

Considering the call site in Function.__call__ vm.make_frame(...) seems to reset the local scope for the frame to the globals. Wouldn't this cause problems when functions modify their local scope? Is this an optimization or a bug? (I'd assume the later one as the logic in the main byterun repo changed here)

# Function
def __call__(self, *args, **kwargs):
        callargs = inspect.getcallargs(self._func, *args, **kwargs)
        frame = self._vm.make_frame(
            self.func_code, callargs, self.func_globals, {}
        )

# VirtualMachine
def make_frame(self, code, callargs={}, global_names=None, local_names=None):
        if global_names is not None and local_names is not None:
            local_names = global_names
...

Pinging the authors @akaptur @nedbat , if you guys find the time, a short clarification would be appreciated.

@timmwagener timmwagener changed the title Python interpreter frame creation bug? Python interpreter frame scope creation bug? Sep 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant