htmy 0.3.4__tar.gz → 0.3.5__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of htmy might be problematic. Click here for more details.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: htmy
3
- Version: 0.3.4
3
+ Version: 0.3.5
4
4
  Summary: Async, pure-Python rendering engine.
5
5
  License: MIT
6
6
  Author: Peter Volf
@@ -295,6 +295,12 @@ If a component executes a potentially "long-running" synchronous call, it is str
295
295
 
296
296
  In all other cases, it's best to use sync components.
297
297
 
298
+ ## Framework integrations
299
+
300
+ FastAPI:
301
+
302
+ - [FastHX](https://github.com/volfpeter/fasthx)
303
+
298
304
  ## Why
299
305
 
300
306
  At one end of the spectrum, there are the complete application frameworks that combine the server (Python) and client (JavaScript) applications with the entire state management and synchronization into a single Python (an in some cases an additional JavaScript) package. Some of the most popular examples are: [Reflex](https://github.com/reflex-dev/reflex), [NiceGUI](https://github.com/zauberzeug/nicegui/), [ReactPy](https://github.com/reactive-python/reactpy), and [FastUI](https://github.com/pydantic/FastUI).
@@ -276,6 +276,12 @@ If a component executes a potentially "long-running" synchronous call, it is str
276
276
 
277
277
  In all other cases, it's best to use sync components.
278
278
 
279
+ ## Framework integrations
280
+
281
+ FastAPI:
282
+
283
+ - [FastHX](https://github.com/volfpeter/fasthx)
284
+
279
285
  ## Why
280
286
 
281
287
  At one end of the spectrum, there are the complete application frameworks that combine the server (Python) and client (JavaScript) applications with the entire state management and synchronization into a single Python (an in some cases an additional JavaScript) package. Some of the most popular examples are: [Reflex](https://github.com/reflex-dev/reflex), [NiceGUI](https://github.com/zauberzeug/nicegui/), [ReactPy](https://github.com/reactive-python/reactpy), and [FastUI](https://github.com/pydantic/FastUI).
@@ -5,7 +5,7 @@ from collections import ChainMap
5
5
  from collections.abc import Awaitable, Callable, Iterable
6
6
 
7
7
  from .core import ErrorBoundary, xml_format_string
8
- from .typing import Component, ComponentType, Context, ContextProvider, HTMYComponentType
8
+ from .typing import Component, ComponentType, Context
9
9
 
10
10
 
11
11
  class HTMY:
@@ -82,15 +82,19 @@ class HTMY:
82
82
  Returns:
83
83
  The rendered string.
84
84
  """
85
- child_context = context
86
- if isinstance(component, ContextProvider):
87
- extra_context = component.htmy_context()
88
- if isinstance(extra_context, Awaitable):
89
- extra_context = await extra_context
85
+ if isinstance(component, str):
86
+ return self._string_formatter(component)
87
+ else:
88
+ child_context: Context = context
89
+ if hasattr(component, "htmy_context"): # isinstance() is too expensive.
90
+ extra_context: Context | Awaitable[Context] = component.htmy_context()
91
+ if isinstance(extra_context, Awaitable):
92
+ extra_context = await extra_context
90
93
 
91
- child_context = ChainMap(extra_context, context)
94
+ if len(extra_context):
95
+ # Context must not be mutated, so we can ignore that ChainMap expext mutable mappings.
96
+ child_context = ChainMap(extra_context, context) # type: ignore[arg-type]
92
97
 
93
- if isinstance(component, HTMYComponentType):
94
98
  try:
95
99
  children = component.htmy(child_context)
96
100
  if isinstance(children, Awaitable):
@@ -102,7 +106,3 @@ class HTMY:
102
106
  return await self._render_one(component.fallback_component(e), context)
103
107
 
104
108
  raise e
105
- elif isinstance(component, str):
106
- return self._string_formatter(component)
107
- else:
108
- raise TypeError("Unknown component type.")
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "htmy"
3
- version = "0.3.4"
3
+ version = "0.3.5"
4
4
  description = "Async, pure-Python rendering engine."
5
5
  authors = ["Peter Volf <do.volfp@gmail.com>"]
6
6
  license = "MIT"
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes