-
Notifications
You must be signed in to change notification settings - Fork 55
prevent overwriting entity variables #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I don't know why they become unavailable. Is it because the attributes get cleared when you do this? This seems related to issue #9. |
With commit 712692f, state variable setting now preserves attributes. |
While playing around I came across a different problem regarding overwriting variables. Sample code: @time_trigger
def precendce_problem():
log.info(f"precendce_problem: running")
event = None
event.fire("raises Exception")
I came across this, when doing a for loop and naming the variable "state" without thinking too much about it. |
Variable scoping should be the same as Python, and I agree it would be a bug if it wasn't. If you create a local variable it will overwrite a previously defined function or object. The example looks correct to me. This behaves exactly the same in Python and pyscript: bytes.fromhex("1234")
bytes = None
bytes.fromhex("5678") The first call works, and the second one fails with an error:
Here's another example that also works the same in Python and pyscript: import math
print(math.sqrt(2))
math = None
print(math.sqrt(2)) I agree there is a subtle difference in pyscript: yes, |
What you say makes sense, I just never happen to stumble upon it before. Issue can be closed. |
I just accidentally did
and now my lights in Home Assistant became unavailable.
Maybe it an idea to now allow overwriting entities?
The same goes for
state
,service
,task
, etc.The text was updated successfully, but these errors were encountered: