Repository navigation
Plan: fix class bodies that raise leaving pyscript in the wrong scope - #3
honeybeartech-homelab-automation[bot] wants to merge 3 commits into
Conversation
Signed-off-by: Sean Stoube <31805425+HoneyBearTech@users.noreply.github.com>
|
@HoneyBearTech The plan for the class-body try/finally fix is ready. Please approve this PR (or comment "approve") to start the work. |
ast_classdef switches into the class namespace before running the body and only switched back after the body finished normally. When the body raised, pyscript stayed in the class namespace, so after the exception was caught, later statements bound their names in the failed class instead of the script. Inside a function the scope stack was left one entry too long. Run the body in a try/finally so the outer scope is always restored, including for the SyntaxError raised for return or break in a class body. Add tests compared against CPython. Signed-off-by: Sean Stoube <31805425+HoneyBearTech@users.noreply.github.com>
Signed-off-by: Sean Stoube <31805425+HoneyBearTech@users.noreply.github.com>
|
@HoneyBearTech The class-body fix is built and checked, with nothing open. It's ready for your approval. DoneWhen a class body raises an error, pyscript now always steps back out of the class, as real Python does. Before, after a caught error, later lines of the script landed inside the failed class. It's a 9-line change in Checks
Rejected findingsNone. What happens when you approve
Upstream PR title: Restore the scope when a class body raises. The description explains the bug with a short example and mentions the overlap with custom-components#902. To approveApprove this PR (or comment "approve") to finish. Close it to throw the work away. Upstream PR descriptionWhat was broken try:
class Foo:
raise ValueError("boom")
except ValueError:
pass
x = 5 # ended up in the failed class's namespace, not in globalsInside a function, the scope stack was left one entry too long. Why What I changed Testing
Note |
|
@HoneyBearTech Thanks for approving. The fix is on its own clean branch, Click this link, check that the title and description are filled in, then click Create pull request. It opens from your account against custom-components/pyscript: After that, you can close this PR without merging. |
This PR holds the plan for a small upstream fix. It stays on this fork and is never merged. Full plan:
docs/plans/classdef-finally.md. Its base is a copy of upstream's latestmaster, so this PR shows only our changes.The bug. When a class body raises an error, pyscript never leaves the class's scope. Example: with
try: class Foo: raise ValueError ... except ValueError: passat the top of a script, a laterx = 5is stored inside the failed class, not in the script. Real Python stores it in the script. I checked this on upstream's latest code.The fix. Wrap the class body in
try/finally, so pyscript always steps back out, plus tests checked against real Python. That's a few lines ineval.py.How it's sent. One commit on a clean branch from upstream
master, with a prefilled link for you to open the upstream PR. custom-components#902 touches the same lines, so whichever merges second needs a small update. We'd do that.Team: Engineer, Security Officer and Auditor. Research and QA are skipped as too small for this job. The plan check is skipped because its reviewer's monthly quota is used up.
Contribution rules followed:
docs/contributing.rstandtests/README.md, pre-commit (ruff, codespell, pylint, mypy), CI on Python 3.14, one small fix per PR with tests, and commits signed off.Status: built and checked, with nothing open. See the latest report comment.
Approve this PR (or comment "approve") to finish. Close it to throw the work away.