Skip to content

Fix bugs with contextfunction and loop variables#1242

Merged
amy-lei merged 2 commits intopallets:masterfrom
MLH-Fellowship:context-bug
Mar 26, 2021
Merged

Fix bugs with contextfunction and loop variables#1242
amy-lei merged 2 commits intopallets:masterfrom
MLH-Fellowship:context-bug

Conversation

@amy-lei
Copy link
Copy Markdown
Contributor

@amy-lei amy-lei commented Jun 23, 2020

Fixes #768 and #1088 (closed as dupe but turned out to be slightly different)

Summary:

  • Scoped blocks can now access loop and its special variables
  • contextfunction can access variables set inside of loops and blocks
    • Achieved by adding an attribute to Frame, tracking assignments made in loops or blocks, and passing it as extra_kwargs

Files Changed:

  • compiler.py
  • runtime.py
  • test_regression.py

@amy-lei amy-lei marked this pull request as draft June 23, 2020 15:05
@amy-lei amy-lei marked this pull request as ready for review June 25, 2020 15:20
@davidism davidism added this to the 3.0.0 milestone Mar 26, 2021
@amy-lei
Copy link
Copy Markdown
Contributor Author

amy-lei commented Mar 26, 2021

Had a discussion with @davidism. Having both a loop_frame and block_frame attribute can be a bit redundant, especially since it's duplicate work until you choose which context to copy. Perhaps it can be reduced something like frame_type.

However, at the moment, there doesn't seem to be other block tags with this context access issue. So when one does come up, we can refactor/address this then.

@amy-lei amy-lei merged commit f71f5eb into pallets:master Mar 26, 2021
@amy-lei amy-lei deleted the context-bug branch March 26, 2021 22:44
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Apr 10, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Loop variables in custom python contextfunction

2 participants