From 52001b58b7298b76b100401373baac6fbf9ddfdc Mon Sep 17 00:00:00 2001 From: Barret Schloerke Date: Fri, 7 Jul 2023 16:17:00 -0400 Subject: [PATCH 1/5] Update `click` to >= v8.1.4 --- setup.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index 2818ade08..fa94386aa 100644 --- a/setup.cfg +++ b/setup.cfg @@ -38,7 +38,7 @@ install_requires = websockets>=10.0 python-multipart htmltools>=0.2.1 - click>=8.0.3 + click>=8.1.4 markdown-it-py>=1.1.0 # This is needed for markdown-it-py. Without it, when loading shiny/ui/_markdown.py, # Python emits the following: "UserWarning: The 'tasklists' feature of GitHub From 772841048b82c55d7877ec98581c33ab2f3a9fe8 Mon Sep 17 00:00:00 2001 From: Barret Schloerke Date: Fri, 7 Jul 2023 16:20:59 -0400 Subject: [PATCH 2/5] Set `name` in `click.group(name="main")` --- shiny/_main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shiny/_main.py b/shiny/_main.py index b74e6ab66..ebe3c613c 100644 --- a/shiny/_main.py +++ b/shiny/_main.py @@ -21,7 +21,7 @@ from . import _autoreload, _hostenv, _static, _utils -@click.group() # pyright: ignore[reportUnknownMemberType] +@click.group("main") def main() -> None: pass @@ -253,7 +253,7 @@ def run_app( maybe_setup_rsw_proxying(log_config) uvicorn.run( # pyright: ignore[reportUnknownMemberType] - app, # pyright: ignore[reportGeneralTypeIssues] + app, host=host, port=port, ws_max_size=ws_max_size, From 6b3275b135273a41c01dd26d9a3de43232c63cbd Mon Sep 17 00:00:00 2001 From: Barret Schloerke Date: Fri, 7 Jul 2023 16:21:39 -0400 Subject: [PATCH 3/5] Use a TypedDict for `reload_args` to use explicit keys --- shiny/_main.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/shiny/_main.py b/shiny/_main.py index ebe3c613c..29831375b 100644 --- a/shiny/_main.py +++ b/shiny/_main.py @@ -10,7 +10,7 @@ import sys import types from pathlib import Path -from typing import Any, Optional +from typing import Any, NotRequired, Optional, TypedDict import click import uvicorn @@ -233,7 +233,7 @@ def run_app( else: setup_hot_reload(log_config, autoreload_port, port, launch_browser) - reload_args: dict[str, bool | str | list[str]] = {} + reload_args: ReloadArgs = {} if reload: reload_dirs = [] if app_dir is not None: @@ -446,3 +446,9 @@ def static_assets(command: str) -> None: _static.print_shinylive_local_info() else: raise click.UsageError(f"Unknown command: {command}") + + +class ReloadArgs(TypedDict): + reload: NotRequired[bool] + reload_includes: NotRequired[list[str]] + reload_dirs: NotRequired[list[str]] From cba4ebc747b3abf813782af0ff066aeb24891784 Mon Sep 17 00:00:00 2001 From: Barret Schloerke Date: Fri, 7 Jul 2023 16:45:19 -0400 Subject: [PATCH 4/5] Fix typing import location --- shiny/_main.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/shiny/_main.py b/shiny/_main.py index 29831375b..3690751aa 100644 --- a/shiny/_main.py +++ b/shiny/_main.py @@ -10,7 +10,7 @@ import sys import types from pathlib import Path -from typing import Any, NotRequired, Optional, TypedDict +from typing import Any, Optional import click import uvicorn @@ -19,6 +19,7 @@ import shiny from . import _autoreload, _hostenv, _static, _utils +from ._typing_extensions import NotRequired, TypedDict @click.group("main") From db0b088ca3d6e654e17c2088e07d5d8bc6ca6f6b Mon Sep 17 00:00:00 2001 From: Barret Schloerke Date: Fri, 7 Jul 2023 16:55:14 -0400 Subject: [PATCH 5/5] Use familar `__all__` syntax instead of `_: 'A | B' # type: ignore` --- shiny/_typing_extensions.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/shiny/_typing_extensions.py b/shiny/_typing_extensions.py index 94d8f7c56..a07650f1d 100644 --- a/shiny/_typing_extensions.py +++ b/shiny/_typing_extensions.py @@ -2,6 +2,15 @@ # flake8: noqa: F401 # pyright: reportUnusedImport=false +__all__ = ( + "Concatenate", + "ParamSpec", + "TypeGuard", + "NotRequired", + "TypedDict", + "assert_type", +) + import sys @@ -17,10 +26,3 @@ from typing import NotRequired, TypedDict, assert_type else: from typing_extensions import NotRequired, TypedDict, assert_type - - -# The only purpose of the following line is so that pyright will put all of the -# conditional imports into the .pyi file when generating type stubs. Without this line, -# pyright will not include the above imports in the generated .pyi file, and it will -# result in a lot of red squiggles in user code. -_: 'Concatenate[str, ParamSpec("P")] | ParamSpec | TypeGuard | NotRequired | TypedDict | assert_type' # type:ignore