Repository navigation
Plan: fix nested classes stored as a placeholder on the outer class - #4
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 nested class fix is ready. Please approve this PR (or comment "approve") to start the work. |
…#875) A class defined inside a class body was left on the outer class as the internal EvalLocalVar placeholder instead of the class itself. So after the outer class was created, Outer.Inner | None raised the same TypeError as in custom-components#875, and type(Outer.Inner()) is Outer.Inner was False. Before the outer class is created, replace each defined EvalLocalVar in a plain dict class namespace with the value it holds. The placeholders themselves are left alone, so methods that read the nested class by its bare name keep working as before. A class namespace that isn't a plain dict, such as a mapping returned by a custom metaclass __prepare__, is left as it is. Signed-off-by: Sean Stoube <31805425+HoneyBearTech@users.noreply.github.com>
Signed-off-by: Sean Stoube <31805425+HoneyBearTech@users.noreply.github.com>
|
@HoneyBearTech The nested class fix is built and checked, with nothing open. It's ready for your approval. DoneA class defined inside another class is now stored on the outer class as the real class. So Checks
Rejected findings
What happens when you approve
Upstream PR title: Store nested classes themselves on the outer class (custom-components#875) To approveApprove this PR (or comment "approve") to finish. Close it to throw the work away. Upstream PR descriptionWhat was broken class Outer:
class Inner:
pass
class Bar:
y: Outer.Inner | None = None # TypeError: unsupported operand type(s) for |: 'EvalLocalVar' and 'NoneType'
type(Outer.Inner()) is Outer.Inner # FalseThis is the same error as custom-components#875, for a class nested in another class. 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, the last remaining case from custom-components#875. It stays on this fork and is never merged. Full plan:
docs/plans/nested-class-attr.md. Its base is a copy of upstream's latestmaster, so this PR shows only our changes.The bug. A class defined inside another class keeps a pyscript-internal placeholder as the outer class's attribute, not the class itself. So
Outer.Inner | Nonefails with the same error as custom-components#875, for example in another class's type hints.type(Outer.Inner()) is Outer.Inneralso gives False instead of True. I checked this on upstream's latest code and on custom-components#902's branch.The fix. When the outer class is finished, swap each placeholder for the real class. It's a few lines in
eval.py, plus tests checked against real Python.Kept as it is: today a method can use the nested class by its bare name (
Inner), which real Python doesn't allow. Scripts may rely on that, so the fix leaves it working, and a test pins it.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 and custom-components#906 touch the same function, so whichever merges later needs a small update. We'd do that.Team: Engineer, Security Officer and Auditor. QA is skipped as too small for this job. The plan check is skipped because its reviewer's monthly quota is still 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.