Skip to content

Bug when shadowing a global variable with a local one #445

Description

@vnmabus

First, I have to say that I found this bug when using Chameleon 3.3, and I was able to reproduce it also in 3.10. I did not try more modern versions because I triggered this in code that still uses Python 2.7, which is not supported in Chameleon 4.x. However, looking at the code in the master branch I think this bug has not been fixed yet.

Description of the problem

Suppose that a variable foo is defined globally. Then, in some code block, we define the variable foo again as a local variable. What should happen then?

This case is not 100% clear from the docs. However, what one would expect from other programming languages, and from the original implementation of ZPT is that the local variable definition "shadows" or hides the global one, inside the scope where the local variable "lives".

That is what happens at a first glance in Chameleon too. However, if a macro is invoked inside the scope of the local variable, when the macro returns, the local variable is updated with the value of its global version (even if the value is not changed inside the macro), which is unexpected:

template("econtext.update(rcontext)")

What one would expect instead is that the values are only updated for variables modified inside the macro (thus, only restoring the global value when one leaves the scope of the local redefinition).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions