Comments (5)
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.
from pyscript.
With commit 712692f, state variable setting now preserves attributes.
from pyscript.
While playing around I came across a different problem regarding overwriting variables.
I seems, that declared variables take presedence over provided variables/objects.
Sample code:
@time_trigger
def precendce_problem():
log.info(f"precendce_problem: running")
event = None
event.fire("raises Exception")
precendce_problem: running
Exception in <jupyter_0.precendce_problem> line 35:
event.fire("raises Exception")
^
AttributeError: 'NoneType' object has no attribute 'fire'
I came across this, when doing a for loop and naming the variable "state" without thinking too much about it.
It wouldn't be too much of an issue, if variables would be scoped, but as they are not, weird things can happen if you don't watch out.
from pyscript.
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:
AttributeError: 'NoneType' object has no attribute 'fromhex'
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, event
or state
don't exist as an object. But if it does (ie: you set them to something), that takes precedence over the event.fire
or state.set
functions, which is the same behavior as regular Python.
from pyscript.
What you say makes sense, I just never happen to stumble upon it before. Issue can be closed.
from pyscript.
Related Issues (20)
- 2023.12 Beta - state.set not setting state HOT 1
- [Feature Request] Error/warning when function name is duplicated in code
- Even with supports_response, service is not returning anything HOT 2
- not implemented ast ast_generatorexp HOT 1
- can not import library after reboot of HA
- Expose home assistant jinja template functions HOT 1
- Croniter version conflict HOT 1
- "MQTT entity name starts with the device name in your config"
- Feature Request: Make apps configurable from Home assistant UI
- Feature Request: exclude from recorder
- attribute changes not detected
- "async with" statement fails without target variable assignment
- Newbie help running Python script under pyscript as a service HOT 2
- Translated state HOT 1
- Template evaluation HOT 2
- Exception in <file.pv_excess_control.on_time> line 246 HOT 2
- Issues using yaml module in pyscript HOT 2
- Python 3.11 support removed from Home Assistant HOT 4
- помогите с IMPORT в home asistant HOT 1
- PyRight LSP HOT 9
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pyscript.