Replies: 1 comment
-
I think I've found a workaround, at least in the short term. I'd love to hear it if there might be a better way--the workaround, as you will see, is not the way Python's type-checking should be used. And it might require me to shut up Instead of using
I don't fully know what pitfalls this approach might lead to in general, but I think the chance of running into those with an application like this is probably low. Fun fact: you can even get a list of strings representing the class hierarchy with:
I'm just starting with Pyscript, and it seems like almost literally the next best thing after sliced bread; I'm grateful for it. Thanks to anyone who reads this. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
I hope that there is an answer or workaround to this issue. I'm not new to programming or the Python language, but I'm pretty thin on background on the Python runtime environment or how it changes within the Home Assistant ecosystem. So far I've reached my limits trying to figure something out, and I haven't found a similar discussion.
Inside of a class method defined in my
[config]/pyscript/modules
subdirectory, I check usingisinstance
whether an argument is of type, say,CustomClass
, whereCustomClass
is also defined by me. The test fails unexpectedly. When I probe around in Jupyter, I can see that the class name has been "mangled":By contrast, when I load the same code using command-line
python
(not Jupyter), the type is reported asmodulename.CustomClass
.Unfortunately, as I think is covered briefly in the documentation,
pyscript
isn't actually defined, so I don't know how, or whether it's possible, to change the way I'm referring to theCustomClass
type in myisinstance
call--I definitely can't usecustom_components.pyscript.eval.CustomClass
since it's undefined. Or maybe there is a different approach that is worth a try.I can probably go without
isinstance
although it complicatesmypy
type checking and probably will require an approach that comes with a few headaches. Any help would be appreciated.EDIT: The original version of the post referenced "
instanceof
" instead ofisinstance
. I am using the correct function name in my code and in Jupyter, but somehow my brain typedinstanceof
when writing this post (which I think is... JavaScript? sigh).Beta Was this translation helpful? Give feedback.
All reactions