mirror of
https://github.com/pyscript/pyscript.git
synced 2025-12-21 11:15:36 -05:00
fix bug around Element not being able to map global attributes in subclasses
This commit is contained in:
@@ -4,6 +4,21 @@ from pyscript import document, when, window
|
|||||||
from pyweb import JSProperty, pydom
|
from pyweb import JSProperty, pydom
|
||||||
|
|
||||||
|
|
||||||
|
import inspect
|
||||||
|
import sys
|
||||||
|
|
||||||
|
#: A flag to show if MicroPython is the current Python interpreter.
|
||||||
|
is_micropython = "MicroPython" in sys.version
|
||||||
|
|
||||||
|
def getmembers_static(cls):
|
||||||
|
"""Cross-interpreter implementation of inspect.getmembers_static."""
|
||||||
|
|
||||||
|
if is_micropython: # pragma: no cover
|
||||||
|
return [(name, getattr(cls, name)) for name, _ in inspect.getmembers(cls)]
|
||||||
|
|
||||||
|
return inspect.getmembers_static(cls)
|
||||||
|
|
||||||
|
|
||||||
class ElementBase(pydom.Element):
|
class ElementBase(pydom.Element):
|
||||||
tag = "div"
|
tag = "div"
|
||||||
|
|
||||||
@@ -55,7 +70,7 @@ class ElementBase(pydom.Element):
|
|||||||
**kwargs: The properties to set
|
**kwargs: The properties to set
|
||||||
"""
|
"""
|
||||||
# Look at all the properties of the class and see if they were provided in kwargs
|
# Look at all the properties of the class and see if they were provided in kwargs
|
||||||
for attr_name, attr in self.__class__.__dict__.items():
|
for attr_name, attr in getmembers_static(self.__class__):
|
||||||
# For each one, actually check if it is a property of the class and set it
|
# For each one, actually check if it is a property of the class and set it
|
||||||
if isinstance(attr, JSProperty) and attr_name in kwargs:
|
if isinstance(attr, JSProperty) and attr_name in kwargs:
|
||||||
try:
|
try:
|
||||||
|
|||||||
Reference in New Issue
Block a user