Skip to content

Commit

Permalink
code review
Browse files Browse the repository at this point in the history
  • Loading branch information
falkoschindler committed Dec 1, 2023
1 parent a208217 commit 8a330c1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
12 changes: 8 additions & 4 deletions nicegui/page.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ def __call__(self, func: Callable[..., Any]) -> Callable[..., Any]:
core.app.remove_route(self.path) # NOTE make sure only the latest route definition is used
parameters_of_decorated_func = list(inspect.signature(func).parameters.keys())

def warn_about_late_returns(task: asyncio.Task) -> None:
if task.result():
log.error(f'ignoring {task.result()}; it was returned after the html was delivered to the client')
def check_for_late_return_value(task: asyncio.Task) -> None:
if task.result() is not None:
log.error(f'ignoring {task.result()}; it was returned after the HTML had been delivered to the client')

async def decorated(*dec_args, **dec_kwargs) -> Response:
request = dec_kwargs['request']
Expand All @@ -110,7 +110,11 @@ async def wait_for_result() -> None:
if time.time() > deadline:
raise TimeoutError(f'Response not ready after {self.response_timeout} seconds')
await asyncio.sleep(0.1)
result = task.result() if task.done() else task.add_done_callback(warn_about_late_returns) # type: ignore
if task.done():
result = task.result()
else:
result = None
task.add_done_callback(check_for_late_return_value)
if isinstance(result, Response): # NOTE if setup returns a response, we don't need to render the page
return result
binding._refresh_step() # pylint: disable=protected-access
Expand Down
2 changes: 1 addition & 1 deletion tests/screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def assert_py_logger(self, level: str, message: Union[str, re.Pattern]) -> None:
assert record.levelname.strip() == level, f'Expected "{level}" but got "{record.levelname}"'

if isinstance(message, re.Pattern):
assert message.search(record.message), f'Expected "{message}" matching regex but got "{record.message}"'
assert message.search(record.message), f'Expected regex "{message}" but got "{record.message}"'
else:
assert record.message.strip() == message, f'Expected "{message}" but got "{record.message}"'
finally:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ async def page(client: Client):

screen.open('/')
screen.should_contain('NiceGUI page')
screen.assert_py_logger('ERROR', re.compile('it was returned after the html was delivered to the client'))
screen.assert_py_logger('ERROR', re.compile('it was returned after the HTML had been delivered to the client'))


def test_reconnecting_without_page_reload(screen: Screen):
Expand Down

0 comments on commit 8a330c1

Please sign in to comment.