diff --git a/flask_htmx/constants.py b/flask_htmx/constants.py index 4938f99..2a26562 100644 --- a/flask_htmx/constants.py +++ b/flask_htmx/constants.py @@ -1,3 +1,6 @@ +import typing + + #: True and False values for the HX-* request and response headers HX_TRUE = "true" HX_FALSE = "false" @@ -14,6 +17,17 @@ "none", ] +ReSwapType = typing.Literal[ + "innerHTML", + "outerHTML", + "beforebegin", + "afterbegin", + "beforeend", + "afterend", + "delete", + "none", +] + #: If you want to stop polling from a server response you can respond with the HTTP #: response code 286 and the element will cancel the polling. HTMX_STOP_POLLING = 286 diff --git a/flask_htmx/htmx.py b/flask_htmx/htmx.py index 882e9b1..1972479 100644 --- a/flask_htmx/htmx.py +++ b/flask_htmx/htmx.py @@ -16,7 +16,7 @@ class HTMX: - https://github.com/adamchainz/django-htmx """ - def __init__(self, app: Flask = None): + def __init__(self, app: Optional[Flask] = None): self.app = app if app is not None: self.init_app(app) diff --git a/flask_htmx/responses.py b/flask_htmx/responses.py index 1664380..0f5d7de 100644 --- a/flask_htmx/responses.py +++ b/flask_htmx/responses.py @@ -6,7 +6,13 @@ from flask import Response from flask import make_response as flask_make_response -from flask_htmx.constants import HTMX_STOP_POLLING, HX_FALSE, HX_TRUE, RESWAPS +from flask_htmx.constants import ( + HTMX_STOP_POLLING, + HX_FALSE, + HX_TRUE, + RESWAPS, + ReSwapType, +) class HTMXResponseClientRedirect(Response): @@ -41,16 +47,16 @@ def _stringify(val): def make_response( *args: typing.Any, - location: str | dict | None = None, - push_url: str | False | None = None, + location: str | typing.Dict[str, str] | None = None, + push_url: str | typing.Literal[False] | None = None, redirect: str | None = None, refresh: bool = False, - replace_url: str | False | None = None, - reswap: str | None = None, + replace_url: str | typing.Literal[False] | None = None, + reswap: ReSwapType | None = None, retarget: str | None = None, - trigger: str | dict | None = None, - trigger_after_settle: str | dict | None = None, - trigger_after_swap: str | dict | None = None, + trigger: str | typing.Dict[str, str] | None = None, + trigger_after_settle: str | typing.Dict[str, str] | None = None, + trigger_after_swap: str | typing.Dict[str, str] | None = None, ) -> Response: """ This function can be used as a replacement from :code:`flask.make_response` to