Skip to content

Second batch of pyscript fixes (#808, #726, del obj.attr, two docs fixes) - #5

Open
honeybeartech-homelab-automation[bot] wants to merge 7 commits into
team/issues-batch-2-basefrom
team/issues-batch-2
Open

honeybeartech-homelab-automation[bot] wants to merge 7 commits into
team/issues-batch-2-basefrom
team/issues-batch-2

Conversation

@honeybeartech-homelab-automation

@honeybeartech-homelab-automation honeybeartech-homelab-automation Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

This PR holds the second batch of pyscript fixes. It stays on this fork and is never merged. Plan and record: docs/plans/issues-batch-2.md. Its base is a copy of upstream's latest master, so this PR shows only our changes.

What we found. We went through all 138 open upstream issues. Only two are real, still-broken bugs that a small fix can solve, so the five are two bug fixes, one small bug we found while checking, and two docs fixes.

# What was wrong Status
custom-components#808 A decorator written with functools.wraps lost its own code, so its try/except never caught the error. Ready. Fixed, with tests.
custom-components#726 In an app with subfolders, a correct relative import (from .a import foo) failed, and a reload could unload part of the app. Ready. Fixed, with a test. Scripts using the old workaround need a one-word change; the PR text says so.
(no issue) del obj.attr on a normal object failed, because pyscript treated it as deleting a Home Assistant state. Ready. Fixed, with tests.
custom-components#821, custom-components#520, custom-components#265 The docs didn't say which logger names apps and scripts use. Ready. Docs, with a full example.
custom-components#864 The docs didn't say that watch= only fires when a value changes. Ready. Docs, with the workaround.

Left out: generator expressions (custom-components#564), which need the maintainer's buy-in.

How it's sent. After your approval, each fix becomes its own upstream PR on a clean branch cut from upstream master, with a prefilled link for you to open it.

Team: three Engineers, then QA, Security Officer and Auditor. The plan check and the plain-English check were skipped because their reviewer's monthly quota is used up.

Contribution rules followed: docs/contributing.rst and tests/README.md (there's no CONTRIBUTING.md or PR template), pre-commit (ruff, codespell, pylint, mypy), CI on Python 3.14, one small fix per PR with tests, commits signed off.

Approve this PR (or comment "approve") to finish. Close it to throw the work away.

Signed-off-by: Sean Stoube <31805425+HoneyBearTech@users.noreply.github.com>
@honeybeartech-homelab-automation

Copy link
Copy Markdown
Author

@HoneyBearTech The plan for the second batch of pyscript fixes is ready. Only 2 open issues turned out to be real, still-broken bugs, so the five are 2 bug fixes, 1 small bug found while checking, and 2 docs fixes. Please approve this PR (or comment "approve") to start the work.

User decorators got the raw EvalFunc, so functools.wraps() copied the
wrapped function's EvalFunc fields over the wrapper's and the wrapper
ran the wrapped body instead of its own (custom-components#808). Decorators now get an
EvalFuncVar, whose own fields are slots that wraps() can't overwrite,
the EvalFuncVar a decorator returns is kept so __wrapped__ and other
attributes survive, and __name__ and __doc__ work like Python's.

Signed-off-by: Sean Stoube <31805425+HoneyBearTech@users.noreply.github.com>
ast_delete passed every dotted target to State.delete, so del a.x on
a normal object, or del self.x in a method, raised NameError. As with
assignment, a dotted name is now a state only if its first part isn't
defined; otherwise the attribute is deleted from the object, and a
pyscript module's class is marked undefined in place.

Signed-off-by: Sean Stoube <31805425+HoneyBearTech@users.noreply.github.com>
The logging docs only showed the "file" path, so apps (and modules and
scripts) were hard to configure, and they claimed Jupyter shows log output
regardless of the logger settings, which isn't true. Add a table of logging
paths per location, a full logger example, note where internal trigger
messages are logged, and correct the Jupyter note in the reference and
tutorial. Refs custom-components#821, custom-components#520, custom-components#265.

Signed-off-by: Sean Stoube <31805425+HoneyBearTech@users.noreply.github.com>
@state_trigger and its watch= argument only evaluate when a watched value
or attribute changes, so a sensor that repeats the same value (for example
with force_update) never fires them. The docs read as if every update did.
Say so, and show watching the last_updated attribute to trigger on every
update. Refs custom-components#864.

Signed-off-by: Sean Stoube <31805425+HoneyBearTech@users.noreply.github.com>
A module imported from a subfolder (from .subfolder.b import x) got its
parent folder as the base for its own relative imports, so a sibling
import (from .a import foo) failed, and imports from plain modules were
registered under phantom contexts such as apps.myapp.subfolder.b.a that
were unloaded on the next reload. Use the module's own folder as the
base and resolve a plain module's relative imports against its package.
Fixes custom-components#726.

Signed-off-by: Sean Stoube <31805425+HoneyBearTech@users.noreply.github.com>
Signed-off-by: Sean Stoube <31805425+HoneyBearTech@users.noreply.github.com>
@honeybeartech-homelab-automation honeybeartech-homelab-automation Bot changed the title Plan: second batch of pyscript fixes (#808, #726, del obj.attr, two docs fixes) Second batch of pyscript fixes (#808, #726, del obj.attr, two docs fixes) Nov 21, 2026
@honeybeartech-homelab-automation

Copy link
Copy Markdown
Author

@HoneyBearTech The second batch of pyscript fixes is built and checked, with nothing open. It's ready for your approval.

Done

Five fixes are ready, each as one commit that applies on its own to upstream's latest code:

Checks

  • QA: passed. All 207 tests, ruff, pylint, mypy, codespell and a strict docs build pass on Python 3.14. Each fix also passes on its own. The new tests fail without the fixes. hassfest only runs on GitHub.
  • Security: clear.
  • Audit: one must-fix, now fixed: the Relative import not working as intended custom-components/pyscript#726 fix would have mistaken an app for a plain file on Windows. The tests pass after the fix. That change was checked by rerunning the checks, not by a second audit.
  • Plan check and plain-English check: skipped, because the reviewer's monthly quota is used up.

Rejected findings

  • del mod.Foo leaves hasattr(mod, "Foo") True (a class defined in another pyscript module). Not changed: pyscript keeps an empty placeholder there so the module's own functions see the class as gone. A plain del Foo already works this way. It's a rare case and is noted as a known limit.

To approve

Approve this PR (or comment "approve") to finish. Close it to throw the work away.

@honeybeartech-homelab-automation

Copy link
Copy Markdown
Author

@HoneyBearTech Thanks for approving. The five fixes are on their own clean branches on this fork, cut from upstream's latest code (c20990b, which now includes custom-components#908 and custom-components#909). All tests, ruff, mypy and pylint pass on each branch.

Click each link, check that the title and description are filled in, then click Create pull request. Each one opens from your account against custom-components/pyscript:

One small update was needed for custom-components#808: upstream custom-components#909 renamed a field that our fix also touches, so I adjusted that one line.

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

Successfully merging this pull request may close these issues.

1 participant