django-components 0.135__tar.gz → 0.136__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.
- {django_components-0.135/src/django_components.egg-info → django_components-0.136}/PKG-INFO +9 -2
- {django_components-0.135 → django_components-0.136}/README.md +8 -1
- {django_components-0.135 → django_components-0.136}/pyproject.toml +1 -1
- {django_components-0.135 → django_components-0.136}/src/django_components/component.py +0 -99
- {django_components-0.135 → django_components-0.136}/src/django_components/extension.py +6 -1
- {django_components-0.135 → django_components-0.136/src/django_components.egg-info}/PKG-INFO +9 -2
- {django_components-0.135 → django_components-0.136}/src/django_components.egg-info/SOURCES.txt +0 -1
- django_components-0.135/src/django_components/util/validation.py +0 -130
- {django_components-0.135 → django_components-0.136}/LICENSE +0 -0
- {django_components-0.135 → django_components-0.136}/MANIFEST.in +0 -0
- {django_components-0.135 → django_components-0.136}/setup.cfg +0 -0
- {django_components-0.135 → django_components-0.136}/src/django_components/__init__.py +0 -0
- {django_components-0.135 → django_components-0.136}/src/django_components/app_settings.py +0 -0
- {django_components-0.135 → django_components-0.136}/src/django_components/apps.py +0 -0
- {django_components-0.135 → django_components-0.136}/src/django_components/attributes.py +0 -0
- {django_components-0.135 → django_components-0.136}/src/django_components/autodiscovery.py +0 -0
- {django_components-0.135 → django_components-0.136}/src/django_components/cache.py +0 -0
- {django_components-0.135 → django_components-0.136}/src/django_components/commands/__init__.py +0 -0
- {django_components-0.135 → django_components-0.136}/src/django_components/commands/components.py +0 -0
- {django_components-0.135 → django_components-0.136}/src/django_components/commands/create.py +0 -0
- {django_components-0.135 → django_components-0.136}/src/django_components/commands/ext.py +0 -0
- {django_components-0.135 → django_components-0.136}/src/django_components/commands/ext_list.py +0 -0
- {django_components-0.135 → django_components-0.136}/src/django_components/commands/ext_run.py +0 -0
- {django_components-0.135 → django_components-0.136}/src/django_components/commands/list.py +0 -0
- {django_components-0.135 → django_components-0.136}/src/django_components/commands/startcomponent.py +0 -0
- {django_components-0.135 → django_components-0.136}/src/django_components/commands/upgrade.py +0 -0
- {django_components-0.135 → django_components-0.136}/src/django_components/commands/upgradecomponent.py +0 -0
- {django_components-0.135 → django_components-0.136}/src/django_components/compat/__init__.py +0 -0
- {django_components-0.135 → django_components-0.136}/src/django_components/compat/django.py +0 -0
- {django_components-0.135 → django_components-0.136}/src/django_components/component_media.py +0 -0
- {django_components-0.135 → django_components-0.136}/src/django_components/component_registry.py +0 -0
- {django_components-0.135 → django_components-0.136}/src/django_components/components/__init__.py +0 -0
- {django_components-0.135 → django_components-0.136}/src/django_components/components/dynamic.py +0 -0
- {django_components-0.135 → django_components-0.136}/src/django_components/context.py +0 -0
- {django_components-0.135 → django_components-0.136}/src/django_components/dependencies.py +0 -0
- {django_components-0.135 → django_components-0.136}/src/django_components/expression.py +0 -0
- {django_components-0.135 → django_components-0.136}/src/django_components/extensions/__init__.py +0 -0
- {django_components-0.135 → django_components-0.136}/src/django_components/extensions/defaults.py +0 -0
- {django_components-0.135 → django_components-0.136}/src/django_components/extensions/view.py +0 -0
- {django_components-0.135 → django_components-0.136}/src/django_components/finders.py +0 -0
- {django_components-0.135 → django_components-0.136}/src/django_components/library.py +0 -0
- {django_components-0.135 → django_components-0.136}/src/django_components/management/__init__.py +0 -0
- {django_components-0.135 → django_components-0.136}/src/django_components/management/commands/__init__.py +0 -0
- {django_components-0.135 → django_components-0.136}/src/django_components/management/commands/components.py +0 -0
- {django_components-0.135 → django_components-0.136}/src/django_components/management/commands/startcomponent.py +0 -0
- {django_components-0.135 → django_components-0.136}/src/django_components/management/commands/upgradecomponent.py +0 -0
- {django_components-0.135 → django_components-0.136}/src/django_components/middleware.py +0 -0
- {django_components-0.135 → django_components-0.136}/src/django_components/node.py +0 -0
- {django_components-0.135 → django_components-0.136}/src/django_components/perfutil/__init__.py +0 -0
- {django_components-0.135 → django_components-0.136}/src/django_components/perfutil/component.py +0 -0
- {django_components-0.135 → django_components-0.136}/src/django_components/perfutil/provide.py +0 -0
- {django_components-0.135 → django_components-0.136}/src/django_components/provide.py +0 -0
- {django_components-0.135 → django_components-0.136}/src/django_components/py.typed +0 -0
- {django_components-0.135 → django_components-0.136}/src/django_components/slots.py +0 -0
- {django_components-0.135 → django_components-0.136}/src/django_components/static/django_components/django_components.min.js +0 -0
- {django_components-0.135 → django_components-0.136}/src/django_components/tag_formatter.py +0 -0
- {django_components-0.135 → django_components-0.136}/src/django_components/template.py +0 -0
- {django_components-0.135 → django_components-0.136}/src/django_components/template_loader.py +0 -0
- {django_components-0.135 → django_components-0.136}/src/django_components/templatetags/__init__.py +0 -0
- {django_components-0.135 → django_components-0.136}/src/django_components/templatetags/component_tags.py +0 -0
- {django_components-0.135 → django_components-0.136}/src/django_components/testing.py +0 -0
- {django_components-0.135 → django_components-0.136}/src/django_components/types.py +0 -0
- {django_components-0.135 → django_components-0.136}/src/django_components/urls.py +0 -0
- {django_components-0.135 → django_components-0.136}/src/django_components/util/__init__.py +0 -0
- {django_components-0.135 → django_components-0.136}/src/django_components/util/cache.py +0 -0
- {django_components-0.135 → django_components-0.136}/src/django_components/util/command.py +0 -0
- {django_components-0.135 → django_components-0.136}/src/django_components/util/component_highlight.py +0 -0
- {django_components-0.135 → django_components-0.136}/src/django_components/util/context.py +0 -0
- {django_components-0.135 → django_components-0.136}/src/django_components/util/django_monkeypatch.py +0 -0
- {django_components-0.135 → django_components-0.136}/src/django_components/util/exception.py +0 -0
- {django_components-0.135 → django_components-0.136}/src/django_components/util/loader.py +0 -0
- {django_components-0.135 → django_components-0.136}/src/django_components/util/logger.py +0 -0
- {django_components-0.135 → django_components-0.136}/src/django_components/util/misc.py +0 -0
- {django_components-0.135 → django_components-0.136}/src/django_components/util/nanoid.py +0 -0
- {django_components-0.135 → django_components-0.136}/src/django_components/util/routing.py +0 -0
- {django_components-0.135 → django_components-0.136}/src/django_components/util/tag_parser.py +0 -0
- {django_components-0.135 → django_components-0.136}/src/django_components/util/template_parser.py +0 -0
- {django_components-0.135 → django_components-0.136}/src/django_components/util/template_tag.py +0 -0
- {django_components-0.135 → django_components-0.136}/src/django_components/util/testing.py +0 -0
- {django_components-0.135 → django_components-0.136}/src/django_components/util/types.py +0 -0
- {django_components-0.135 → django_components-0.136}/src/django_components/util/weakref.py +0 -0
- {django_components-0.135 → django_components-0.136}/src/django_components.egg-info/dependency_links.txt +0 -0
- {django_components-0.135 → django_components-0.136}/src/django_components.egg-info/requires.txt +0 -0
- {django_components-0.135 → django_components-0.136}/src/django_components.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: django_components
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.136
|
|
4
4
|
Summary: A way to create simple reusable template components in Django.
|
|
5
5
|
Author-email: Emil Stenström <emil@emilstenstrom.se>
|
|
6
6
|
License: MIT
|
|
@@ -359,13 +359,20 @@ Django-components functionality can be extended with "extensions". Extensions al
|
|
|
359
359
|
|
|
360
360
|
- Tap into lifecycle events, such as when a component is created, deleted, or registered.
|
|
361
361
|
- Add new attributes and methods to the components under an extension-specific nested class.
|
|
362
|
+
- Add custom CLI commands.
|
|
363
|
+
- Add custom URLs.
|
|
364
|
+
|
|
365
|
+
Some of the extensions include:
|
|
366
|
+
|
|
367
|
+
- [Django View integration](https://github.com/django-components/django-components/blob/master/src/django_components/extensions/view.py)
|
|
368
|
+
- [Component defaults](https://github.com/django-components/django-components/blob/master/src/django_components/extensions/defaults.py)
|
|
369
|
+
- [Pydantic integration (input validation)](https://github.com/django-components/djc-ext-pydantic)
|
|
362
370
|
|
|
363
371
|
Some of the planned extensions include:
|
|
364
372
|
|
|
365
373
|
- Caching
|
|
366
374
|
- AlpineJS integration
|
|
367
375
|
- Storybook integration
|
|
368
|
-
- Pydantic validation
|
|
369
376
|
- Component-level benchmarking with asv
|
|
370
377
|
|
|
371
378
|
### Simple testing
|
|
@@ -327,13 +327,20 @@ Django-components functionality can be extended with "extensions". Extensions al
|
|
|
327
327
|
|
|
328
328
|
- Tap into lifecycle events, such as when a component is created, deleted, or registered.
|
|
329
329
|
- Add new attributes and methods to the components under an extension-specific nested class.
|
|
330
|
+
- Add custom CLI commands.
|
|
331
|
+
- Add custom URLs.
|
|
332
|
+
|
|
333
|
+
Some of the extensions include:
|
|
334
|
+
|
|
335
|
+
- [Django View integration](https://github.com/django-components/django-components/blob/master/src/django_components/extensions/view.py)
|
|
336
|
+
- [Component defaults](https://github.com/django-components/django-components/blob/master/src/django_components/extensions/defaults.py)
|
|
337
|
+
- [Pydantic integration (input validation)](https://github.com/django-components/djc-ext-pydantic)
|
|
330
338
|
|
|
331
339
|
Some of the planned extensions include:
|
|
332
340
|
|
|
333
341
|
- Caching
|
|
334
342
|
- AlpineJS integration
|
|
335
343
|
- Storybook integration
|
|
336
|
-
- Pydantic validation
|
|
337
344
|
- Component-level benchmarking with asv
|
|
338
345
|
|
|
339
346
|
### Simple testing
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "django_components"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.136"
|
|
8
8
|
requires-python = ">=3.8, <4.0"
|
|
9
9
|
description = "A way to create simple reusable template components in Django."
|
|
10
10
|
keywords = ["django", "components", "css", "js", "html"]
|
|
@@ -85,7 +85,6 @@ from django_components.util.exception import component_error_message
|
|
|
85
85
|
from django_components.util.logger import trace_component_msg
|
|
86
86
|
from django_components.util.misc import gen_id, get_import_path, hash_comp_cls
|
|
87
87
|
from django_components.util.template_tag import TagAttr
|
|
88
|
-
from django_components.util.validation import validate_typed_dict, validate_typed_tuple
|
|
89
88
|
from django_components.util.weakref import cached_ref
|
|
90
89
|
|
|
91
90
|
# TODO_REMOVE_IN_V1 - Users should use top-level import instead
|
|
@@ -1093,10 +1092,6 @@ class Component(
|
|
|
1093
1092
|
render_dependencies: bool = True,
|
|
1094
1093
|
request: Optional[HttpRequest] = None,
|
|
1095
1094
|
) -> str:
|
|
1096
|
-
# NOTE: We must run validation before we normalize the slots, because the normalization
|
|
1097
|
-
# wraps them in functions.
|
|
1098
|
-
self._validate_inputs(args or (), kwargs or {}, slots or {})
|
|
1099
|
-
|
|
1100
1095
|
# Allow to pass down Request object via context.
|
|
1101
1096
|
# `context` may be passed explicitly via `Component.render()` and `Component.render_to_response()`,
|
|
1102
1097
|
# or implicitly via `{% component %}` tag.
|
|
@@ -1230,7 +1225,6 @@ class Component(
|
|
|
1230
1225
|
# TODO - enable JS and CSS vars - EXPOSE AND DOCUMENT AND MAKE NON-NULL
|
|
1231
1226
|
js_data = self.get_js_data(*args, **kwargs) if hasattr(self, "get_js_data") else {} # type: ignore
|
|
1232
1227
|
css_data = self.get_css_data(*args, **kwargs) if hasattr(self, "get_css_data") else {} # type: ignore
|
|
1233
|
-
self._validate_outputs(data=context_data)
|
|
1234
1228
|
|
|
1235
1229
|
extensions.on_component_data(
|
|
1236
1230
|
OnComponentDataContext(
|
|
@@ -1489,99 +1483,6 @@ class Component(
|
|
|
1489
1483
|
|
|
1490
1484
|
return norm_fills
|
|
1491
1485
|
|
|
1492
|
-
# #####################################
|
|
1493
|
-
# VALIDATION
|
|
1494
|
-
# #####################################
|
|
1495
|
-
|
|
1496
|
-
def _get_types(self) -> Optional[Tuple[Any, Any, Any, Any, Any, Any]]:
|
|
1497
|
-
"""
|
|
1498
|
-
Extract the types passed to the Component class.
|
|
1499
|
-
|
|
1500
|
-
So if a component subclasses Component class like so
|
|
1501
|
-
|
|
1502
|
-
```py
|
|
1503
|
-
class MyComp(Component[MyArgs, MyKwargs, MySlots, MyData, MyJsData, MyCssData]):
|
|
1504
|
-
...
|
|
1505
|
-
```
|
|
1506
|
-
|
|
1507
|
-
Then we want to extract the tuple (MyArgs, MyKwargs, MySlots, MyData, MyJsData, MyCssData).
|
|
1508
|
-
|
|
1509
|
-
Returns `None` if types were not provided. That is, the class was subclassed
|
|
1510
|
-
as:
|
|
1511
|
-
|
|
1512
|
-
```py
|
|
1513
|
-
class MyComp(Component):
|
|
1514
|
-
...
|
|
1515
|
-
```
|
|
1516
|
-
"""
|
|
1517
|
-
# For efficiency, the type extraction is done only once.
|
|
1518
|
-
# If `self._types` is `False`, that means that the types were not specified.
|
|
1519
|
-
# If `self._types` is `None`, then this is the first time running this method.
|
|
1520
|
-
# Otherwise, `self._types` should be a tuple of (Args, Kwargs, Data, Slots)
|
|
1521
|
-
if self._types == False: # noqa: E712
|
|
1522
|
-
return None
|
|
1523
|
-
elif self._types:
|
|
1524
|
-
return self._types
|
|
1525
|
-
|
|
1526
|
-
# Since a class can extend multiple classes, e.g.
|
|
1527
|
-
#
|
|
1528
|
-
# ```py
|
|
1529
|
-
# class MyClass(BaseOne, BaseTwo, ...):
|
|
1530
|
-
# ...
|
|
1531
|
-
# ```
|
|
1532
|
-
#
|
|
1533
|
-
# Then we need to find the base class that is our `Component` class.
|
|
1534
|
-
#
|
|
1535
|
-
# NOTE: __orig_bases__ is a tuple of _GenericAlias
|
|
1536
|
-
# See https://github.com/python/cpython/blob/709ef004dffe9cee2a023a3c8032d4ce80513582/Lib/typing.py#L1244
|
|
1537
|
-
# And https://github.com/python/cpython/issues/101688
|
|
1538
|
-
generics_bases: Tuple[Any, ...] = self.__orig_bases__ # type: ignore[attr-defined]
|
|
1539
|
-
component_generics_base = None
|
|
1540
|
-
for base in generics_bases:
|
|
1541
|
-
origin_cls = base.__origin__
|
|
1542
|
-
if origin_cls == Component or issubclass(origin_cls, Component):
|
|
1543
|
-
component_generics_base = base
|
|
1544
|
-
break
|
|
1545
|
-
|
|
1546
|
-
if not component_generics_base:
|
|
1547
|
-
# If we get here, it means that the Component class wasn't supplied any generics
|
|
1548
|
-
self._types = False
|
|
1549
|
-
return None
|
|
1550
|
-
|
|
1551
|
-
# If we got here, then we've found ourselves the typed Component class, e.g.
|
|
1552
|
-
#
|
|
1553
|
-
# `Component(Tuple[int], MyKwargs, MySlots, Any, Any, Any)`
|
|
1554
|
-
#
|
|
1555
|
-
# By accessing the __args__, we access individual types between the brackets, so
|
|
1556
|
-
#
|
|
1557
|
-
# (Tuple[int], MyKwargs, MySlots, Any, Any, Any)
|
|
1558
|
-
args_type, kwargs_type, slots_type, data_type, js_data_type, css_data_type = component_generics_base.__args__
|
|
1559
|
-
|
|
1560
|
-
self._types = args_type, kwargs_type, slots_type, data_type, js_data_type, css_data_type
|
|
1561
|
-
return self._types
|
|
1562
|
-
|
|
1563
|
-
def _validate_inputs(self, args: Tuple, kwargs: Any, slots: Any) -> None:
|
|
1564
|
-
maybe_inputs = self._get_types()
|
|
1565
|
-
if maybe_inputs is None:
|
|
1566
|
-
return
|
|
1567
|
-
args_type, kwargs_type, slots_type, data_type, js_data_type, css_data_type = maybe_inputs
|
|
1568
|
-
|
|
1569
|
-
# Validate args
|
|
1570
|
-
validate_typed_tuple(args, args_type, f"Component '{self.name}'", "positional argument")
|
|
1571
|
-
# Validate kwargs
|
|
1572
|
-
validate_typed_dict(kwargs, kwargs_type, f"Component '{self.name}'", "keyword argument")
|
|
1573
|
-
# Validate slots
|
|
1574
|
-
validate_typed_dict(slots, slots_type, f"Component '{self.name}'", "slot")
|
|
1575
|
-
|
|
1576
|
-
def _validate_outputs(self, data: Any) -> None:
|
|
1577
|
-
maybe_inputs = self._get_types()
|
|
1578
|
-
if maybe_inputs is None:
|
|
1579
|
-
return
|
|
1580
|
-
args_type, kwargs_type, slots_type, data_type, js_data_type, css_data_type = maybe_inputs
|
|
1581
|
-
|
|
1582
|
-
# Validate data
|
|
1583
|
-
validate_typed_dict(data, data_type, f"Component '{self.name}'", "data")
|
|
1584
|
-
|
|
1585
1486
|
|
|
1586
1487
|
# Perf
|
|
1587
1488
|
# Each component may use different start and end tags. We represent this
|
|
@@ -3,7 +3,7 @@ from typing import TYPE_CHECKING, Any, Callable, Dict, List, NamedTuple, Tuple,
|
|
|
3
3
|
|
|
4
4
|
import django.urls
|
|
5
5
|
from django.template import Context
|
|
6
|
-
from django.urls import URLResolver
|
|
6
|
+
from django.urls import URLResolver, get_resolver, get_urlconf
|
|
7
7
|
|
|
8
8
|
from django_components.app_settings import app_settings
|
|
9
9
|
from django_components.compat.django import routes_to_django
|
|
@@ -634,6 +634,11 @@ class ExtensionManager:
|
|
|
634
634
|
ext_url_resolver.urlconf_name = urls
|
|
635
635
|
ext_url_resolver.url_patterns = urls
|
|
636
636
|
|
|
637
|
+
# Rebuild URL resolver cache to be able to resolve the new routes by their names.
|
|
638
|
+
urlconf = get_urlconf()
|
|
639
|
+
resolver = get_resolver(urlconf)
|
|
640
|
+
resolver._populate()
|
|
641
|
+
|
|
637
642
|
def get_extension(self, name: str) -> ComponentExtension:
|
|
638
643
|
for extension in self.extensions:
|
|
639
644
|
if extension.name == name:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: django_components
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.136
|
|
4
4
|
Summary: A way to create simple reusable template components in Django.
|
|
5
5
|
Author-email: Emil Stenström <emil@emilstenstrom.se>
|
|
6
6
|
License: MIT
|
|
@@ -359,13 +359,20 @@ Django-components functionality can be extended with "extensions". Extensions al
|
|
|
359
359
|
|
|
360
360
|
- Tap into lifecycle events, such as when a component is created, deleted, or registered.
|
|
361
361
|
- Add new attributes and methods to the components under an extension-specific nested class.
|
|
362
|
+
- Add custom CLI commands.
|
|
363
|
+
- Add custom URLs.
|
|
364
|
+
|
|
365
|
+
Some of the extensions include:
|
|
366
|
+
|
|
367
|
+
- [Django View integration](https://github.com/django-components/django-components/blob/master/src/django_components/extensions/view.py)
|
|
368
|
+
- [Component defaults](https://github.com/django-components/django-components/blob/master/src/django_components/extensions/defaults.py)
|
|
369
|
+
- [Pydantic integration (input validation)](https://github.com/django-components/djc-ext-pydantic)
|
|
362
370
|
|
|
363
371
|
Some of the planned extensions include:
|
|
364
372
|
|
|
365
373
|
- Caching
|
|
366
374
|
- AlpineJS integration
|
|
367
375
|
- Storybook integration
|
|
368
|
-
- Pydantic validation
|
|
369
376
|
- Component-level benchmarking with asv
|
|
370
377
|
|
|
371
378
|
### Simple testing
|
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
import sys
|
|
2
|
-
import typing
|
|
3
|
-
from typing import Any, Mapping, Tuple, get_type_hints
|
|
4
|
-
|
|
5
|
-
# Get all types that users may use from the `typing` module.
|
|
6
|
-
#
|
|
7
|
-
# These are the types that we do NOT try to resolve when it's a typed generic,
|
|
8
|
-
# e.g. `Union[int, str]`.
|
|
9
|
-
# If we get a typed generic that's NOT part of this set, we assume it's a user-made
|
|
10
|
-
# generic, e.g. `Component[Args, Kwargs]`. In such case we assert that a given value
|
|
11
|
-
# is an instance of the base class, e.g. `Component`.
|
|
12
|
-
_typing_exports = frozenset(
|
|
13
|
-
[
|
|
14
|
-
value
|
|
15
|
-
for value in typing.__dict__.values()
|
|
16
|
-
if isinstance(
|
|
17
|
-
value,
|
|
18
|
-
(
|
|
19
|
-
typing._SpecialForm,
|
|
20
|
-
# Used in 3.8 and 3.9
|
|
21
|
-
getattr(typing, "_GenericAlias", ()),
|
|
22
|
-
# Used in 3.11+ (possibly 3.10?)
|
|
23
|
-
getattr(typing, "_SpecialGenericAlias", ()),
|
|
24
|
-
),
|
|
25
|
-
)
|
|
26
|
-
]
|
|
27
|
-
)
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
def _prepare_type_for_validation(the_type: Any) -> Any:
|
|
31
|
-
# If we got a typed generic (AKA "subscripted" generic), e.g.
|
|
32
|
-
# `Component[CompArgs, CompKwargs, ...]`
|
|
33
|
-
# then we cannot use that generic in `isintance()`, because we get this error:
|
|
34
|
-
# `TypeError("Subscripted generics cannot be used with class and instance checks")`
|
|
35
|
-
#
|
|
36
|
-
# Instead, we resolve the generic to its original class, e.g. `Component`,
|
|
37
|
-
# which can then be used in instance assertion.
|
|
38
|
-
if hasattr(the_type, "__origin__"):
|
|
39
|
-
is_custom_typing = the_type.__origin__ not in _typing_exports
|
|
40
|
-
if is_custom_typing:
|
|
41
|
-
return the_type.__origin__
|
|
42
|
-
else:
|
|
43
|
-
return the_type
|
|
44
|
-
else:
|
|
45
|
-
return the_type
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
# NOTE: tuple_type is a _GenericAlias - See https://stackoverflow.com/questions/74412803
|
|
49
|
-
def validate_typed_tuple(
|
|
50
|
-
value: Tuple[Any, ...],
|
|
51
|
-
tuple_type: Any,
|
|
52
|
-
prefix: str,
|
|
53
|
-
kind: str,
|
|
54
|
-
) -> None:
|
|
55
|
-
# `Any` type is the signal that we should skip validation
|
|
56
|
-
if tuple_type == Any:
|
|
57
|
-
return
|
|
58
|
-
|
|
59
|
-
# We do two kinds of validation with the given Tuple type:
|
|
60
|
-
# 1. We check whether there are any extra / missing positional args
|
|
61
|
-
# 2. We look at the members of the Tuple (which are types themselves),
|
|
62
|
-
# and check if our concrete list / tuple has correct types under correct indices.
|
|
63
|
-
expected_pos_args = len(tuple_type.__args__)
|
|
64
|
-
actual_pos_args = len(value)
|
|
65
|
-
if expected_pos_args > actual_pos_args:
|
|
66
|
-
# Generate errors like below (listed for searchability)
|
|
67
|
-
# `Component 'name' expected 3 positional arguments, got 2`
|
|
68
|
-
raise TypeError(f"{prefix} expected {expected_pos_args} {kind}s, got {actual_pos_args}")
|
|
69
|
-
|
|
70
|
-
for index, arg_type in enumerate(tuple_type.__args__):
|
|
71
|
-
arg = value[index]
|
|
72
|
-
arg_type = _prepare_type_for_validation(arg_type)
|
|
73
|
-
if sys.version_info >= (3, 11) and not isinstance(arg, arg_type):
|
|
74
|
-
# Generate errors like below (listed for searchability)
|
|
75
|
-
# `Component 'name' expected positional argument at index 0 to be <class 'int'>, got 123.5 of type <class 'float'>` # noqa: E501
|
|
76
|
-
raise TypeError(
|
|
77
|
-
f"{prefix} expected {kind} at index {index} to be {arg_type}, got {arg} of type {type(arg)}"
|
|
78
|
-
)
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
# NOTE:
|
|
82
|
-
# - `dict_type` can be a `TypedDict` or `Any` as the types themselves
|
|
83
|
-
# - `value` is expected to be TypedDict, the base `TypedDict` type cannot be used
|
|
84
|
-
# in function signature (only its subclasses can), so we specify the type as Mapping.
|
|
85
|
-
# See https://stackoverflow.com/questions/74412803
|
|
86
|
-
def validate_typed_dict(value: Mapping[str, Any], dict_type: Any, prefix: str, kind: str) -> None:
|
|
87
|
-
# `Any` type is the signal that we should skip validation
|
|
88
|
-
if dict_type == Any:
|
|
89
|
-
return
|
|
90
|
-
|
|
91
|
-
# See https://stackoverflow.com/a/76527675
|
|
92
|
-
# And https://stackoverflow.com/a/71231688
|
|
93
|
-
required_kwargs = dict_type.__required_keys__
|
|
94
|
-
unseen_keys = set(value.keys())
|
|
95
|
-
|
|
96
|
-
# For each entry in the TypedDict, we do two kinds of validation:
|
|
97
|
-
# 1. We check whether there are any extra / missing keys
|
|
98
|
-
# 2. We look at the values of TypedDict entries (which are types themselves),
|
|
99
|
-
# and check if our concrete dict has correct types under correct keys.
|
|
100
|
-
for key, kwarg_type in get_type_hints(dict_type).items():
|
|
101
|
-
if key not in value:
|
|
102
|
-
if key in required_kwargs:
|
|
103
|
-
# Generate errors like below (listed for searchability)
|
|
104
|
-
# `Component 'name' is missing a required keyword argument 'key'`
|
|
105
|
-
# `Component 'name' is missing a required slot argument 'key'`
|
|
106
|
-
# `Component 'name' is missing a required data argument 'key'`
|
|
107
|
-
raise TypeError(f"{prefix} is missing a required {kind} '{key}'")
|
|
108
|
-
else:
|
|
109
|
-
unseen_keys.remove(key)
|
|
110
|
-
kwarg = value[key]
|
|
111
|
-
kwarg_type = _prepare_type_for_validation(kwarg_type)
|
|
112
|
-
|
|
113
|
-
# NOTE: `isinstance()` cannot be used with the version of TypedDict prior to 3.11.
|
|
114
|
-
# So we do type validation for TypedDicts only in 3.11 and later.
|
|
115
|
-
if sys.version_info >= (3, 11) and not isinstance(kwarg, kwarg_type):
|
|
116
|
-
# Generate errors like below (listed for searchability)
|
|
117
|
-
# `Component 'name' expected keyword argument 'key' to be <class 'int'>, got 123.4 of type <class 'float'>` # noqa: E501
|
|
118
|
-
# `Component 'name' expected slot 'key' to be <class 'int'>, got 123.4 of type <class 'float'>`
|
|
119
|
-
# `Component 'name' expected data 'key' to be <class 'int'>, got 123.4 of type <class 'float'>`
|
|
120
|
-
raise TypeError(
|
|
121
|
-
f"{prefix} expected {kind} '{key}' to be {kwarg_type}, got {kwarg} of type {type(kwarg)}"
|
|
122
|
-
)
|
|
123
|
-
|
|
124
|
-
if unseen_keys:
|
|
125
|
-
formatted_keys = ", ".join([f"'{key}'" for key in unseen_keys])
|
|
126
|
-
# Generate errors like below (listed for searchability)
|
|
127
|
-
# `Component 'name' got unexpected keyword argument keys 'invalid_key'`
|
|
128
|
-
# `Component 'name' got unexpected slot keys 'invalid_key'`
|
|
129
|
-
# `Component 'name' got unexpected data keys 'invalid_key'`
|
|
130
|
-
raise TypeError(f"{prefix} got unexpected {kind} keys {formatted_keys}")
|
|
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
|
{django_components-0.135 → django_components-0.136}/src/django_components/commands/__init__.py
RENAMED
|
File without changes
|
{django_components-0.135 → django_components-0.136}/src/django_components/commands/components.py
RENAMED
|
File without changes
|
{django_components-0.135 → django_components-0.136}/src/django_components/commands/create.py
RENAMED
|
File without changes
|
|
File without changes
|
{django_components-0.135 → django_components-0.136}/src/django_components/commands/ext_list.py
RENAMED
|
File without changes
|
{django_components-0.135 → django_components-0.136}/src/django_components/commands/ext_run.py
RENAMED
|
File without changes
|
|
File without changes
|
{django_components-0.135 → django_components-0.136}/src/django_components/commands/startcomponent.py
RENAMED
|
File without changes
|
{django_components-0.135 → django_components-0.136}/src/django_components/commands/upgrade.py
RENAMED
|
File without changes
|
|
File without changes
|
{django_components-0.135 → django_components-0.136}/src/django_components/compat/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
{django_components-0.135 → django_components-0.136}/src/django_components/component_media.py
RENAMED
|
File without changes
|
{django_components-0.135 → django_components-0.136}/src/django_components/component_registry.py
RENAMED
|
File without changes
|
{django_components-0.135 → django_components-0.136}/src/django_components/components/__init__.py
RENAMED
|
File without changes
|
{django_components-0.135 → django_components-0.136}/src/django_components/components/dynamic.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{django_components-0.135 → django_components-0.136}/src/django_components/extensions/__init__.py
RENAMED
|
File without changes
|
{django_components-0.135 → django_components-0.136}/src/django_components/extensions/defaults.py
RENAMED
|
File without changes
|
{django_components-0.135 → django_components-0.136}/src/django_components/extensions/view.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{django_components-0.135 → django_components-0.136}/src/django_components/management/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{django_components-0.135 → django_components-0.136}/src/django_components/perfutil/__init__.py
RENAMED
|
File without changes
|
{django_components-0.135 → django_components-0.136}/src/django_components/perfutil/component.py
RENAMED
|
File without changes
|
{django_components-0.135 → django_components-0.136}/src/django_components/perfutil/provide.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{django_components-0.135 → django_components-0.136}/src/django_components/template_loader.py
RENAMED
|
File without changes
|
{django_components-0.135 → django_components-0.136}/src/django_components/templatetags/__init__.py
RENAMED
|
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
|
{django_components-0.135 → django_components-0.136}/src/django_components/util/django_monkeypatch.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{django_components-0.135 → django_components-0.136}/src/django_components/util/tag_parser.py
RENAMED
|
File without changes
|
{django_components-0.135 → django_components-0.136}/src/django_components/util/template_parser.py
RENAMED
|
File without changes
|
{django_components-0.135 → django_components-0.136}/src/django_components/util/template_tag.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{django_components-0.135 → django_components-0.136}/src/django_components.egg-info/requires.txt
RENAMED
|
File without changes
|
{django_components-0.135 → django_components-0.136}/src/django_components.egg-info/top_level.txt
RENAMED
|
File without changes
|