Skip to content

Commit

Permalink
Improve Headers type
Browse files Browse the repository at this point in the history
  • Loading branch information
paveldedik committed Mar 12, 2024
1 parent 656dcda commit bfcfa54
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
6 changes: 3 additions & 3 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ Ludic is a lightweight framework for building HTML pages with component approach
## Example

```python
from ludic.html import b, p
from ludic.html import b, span
from ludic.web import LudicApp

app = LudicApp()

@app.get("/")
async def homepage() -> p:
return p(f"Hello {b("world")}!", id="greetings")
async def homepage() -> span:
return span(f"Hello {b("world")}!", id="greetings")
```

## Requirements
Expand Down
15 changes: 9 additions & 6 deletions ludic/types.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from collections.abc import Mapping
from collections.abc import Iterable, Mapping
from typing import TypedDict

from .base import (
Expand All @@ -22,21 +22,24 @@
TChildrenArgs,
)

Headers = Mapping[str, str | Mapping[str, str]]
JSONType = (
Mapping[str, "JSONType"] | Iterable["JSONType"] | str | int | float | bool | None
)
Headers = Mapping[str, JSONType]
HXHeaders = TypedDict(
"HXHeaders",
{
"HX-Location": str | Mapping[str, str],
"HX-Location": JSONType,
"HX-Push-Url": str,
"HX-Redirect": str,
"HX-Refresh": bool,
"HX-Replace-Url": str,
"HX-Reswap": str,
"HX-Retarget": str,
"HX-Reselect": str,
"HX-Trigger": str | Mapping[str, str],
"HX-Trigger-After-Settle": str | Mapping[str, str],
"HX-Trigger-After-Swap": str | Mapping[str, str],
"HX-Trigger": JSONType,
"HX-Trigger-After-Settle": JSONType,
"HX-Trigger-After-Swap": JSONType,
},
total=False,
)
Expand Down
6 changes: 4 additions & 2 deletions ludic/web/datastructures.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import json
from collections.abc import Mapping, MutableMapping
from collections.abc import MutableMapping
from typing import Any
from urllib.parse import urlencode

Expand All @@ -12,6 +12,8 @@
URLPath as BaseURLPath,
)

from ludic import types

__all__ = ("FormData", "Headers", "QueryParams", "URLPath")


Expand All @@ -20,7 +22,7 @@ class Headers(BaseHeaders):

def __init__(
self,
headers: Mapping[str, Any] | None = None,
headers: types.Headers | None = None,
raw: list[tuple[bytes, bytes]] | None = None,
scope: MutableMapping[str, Any] | None = None,
) -> None:
Expand Down

0 comments on commit bfcfa54

Please sign in to comment.