[pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci
This commit is contained in:
pre-commit-ci[bot]
2024-10-24 13:22:29 +00:00
parent 9db8b13d9c
commit b33661ff8e
2 changed files with 14 additions and 10 deletions

View File

@@ -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:

View File

@@ -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