mirror of
https://github.com/pyscript/pyscript.git
synced 2025-12-19 18:27:29 -05:00
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
This commit is contained in:
@@ -20,8 +20,8 @@ def when(target, *args, **kwargs):
|
||||
|
||||
disconnect(whenable, handler)
|
||||
|
||||
|
||||
"""
|
||||
|
||||
"""
|
||||
# If "when" is called as a function, try to grab the handler from the
|
||||
# arguments. If there's no handler, this must be a decorator based call.
|
||||
handler = None
|
||||
@@ -35,7 +35,7 @@ def when(target, *args, **kwargs):
|
||||
whenable = hasattr(target, "__when__")
|
||||
# If not when-able, the DOM selector for the target event.
|
||||
if not whenable:
|
||||
# The target is an event linked to a DOM selector. Extract the
|
||||
# The target is an event linked to a DOM selector. Extract the
|
||||
# selector from the arguments or keyword arguments.
|
||||
if args:
|
||||
selector = args[0]
|
||||
@@ -68,11 +68,15 @@ def when(target, *args, **kwargs):
|
||||
if not sig.parameters:
|
||||
# Function is async: must be awaited
|
||||
if inspect.iscoroutinefunction(func):
|
||||
|
||||
async def wrapper(*args, **kwargs):
|
||||
await func()
|
||||
|
||||
else:
|
||||
|
||||
def wrapper(*args, **kwargs):
|
||||
func()
|
||||
|
||||
else:
|
||||
wrapper = func
|
||||
except AttributeError:
|
||||
|
||||
@@ -231,7 +231,7 @@ def test_when_decorates_a_whenable():
|
||||
self.handler = None
|
||||
self.args = None
|
||||
self.kwargs = None
|
||||
|
||||
|
||||
def trigger(self):
|
||||
"""
|
||||
Triggers the whenable object, resulting in the handler being
|
||||
@@ -242,7 +242,7 @@ def test_when_decorates_a_whenable():
|
||||
"args": self.args,
|
||||
"kwargs": self.kwargs,
|
||||
}
|
||||
self.handler(result) # call the handler
|
||||
self.handler(result) # call the handler
|
||||
|
||||
def __when__(self, handler, *args, **kwargs):
|
||||
"""
|
||||
@@ -269,7 +269,7 @@ def test_when_decorates_a_whenable():
|
||||
counter += 1
|
||||
assert result["args"] == ("foo", "bar")
|
||||
assert result["kwargs"] == {"baz": "qux"}
|
||||
|
||||
|
||||
# The function should not be called until the whenable object is triggered.
|
||||
assert counter == 0
|
||||
# Trigger the whenable object.
|
||||
@@ -294,7 +294,7 @@ def test_when_called_with_a_whenable():
|
||||
self.handler = None
|
||||
self.args = None
|
||||
self.kwargs = None
|
||||
|
||||
|
||||
def trigger(self):
|
||||
"""
|
||||
Triggers the whenable object, resulting in the handler being
|
||||
@@ -305,7 +305,7 @@ def test_when_called_with_a_whenable():
|
||||
"args": self.args,
|
||||
"kwargs": self.kwargs,
|
||||
}
|
||||
self.handler(result) # call the handler
|
||||
self.handler(result) # call the handler
|
||||
|
||||
def __when__(self, handler, *args, **kwargs):
|
||||
"""
|
||||
@@ -330,7 +330,7 @@ def test_when_called_with_a_whenable():
|
||||
counter += 1
|
||||
assert result["args"] == ("foo", "bar")
|
||||
assert result["kwargs"] == {"baz": "qux"}
|
||||
|
||||
|
||||
# When as a function.
|
||||
web.when(whenable, handler, "foo", "bar", baz="qux")
|
||||
|
||||
@@ -340,4 +340,4 @@ def test_when_called_with_a_whenable():
|
||||
whenable.trigger()
|
||||
# The function should have been called when the whenable object was
|
||||
# triggered.
|
||||
assert counter == 1
|
||||
assert counter == 1
|
||||
|
||||
Reference in New Issue
Block a user