TypeDAL 3.6.0__tar.gz → 3.7.1__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 TypeDAL might be problematic. Click here for more details.
- {typedal-3.6.0 → typedal-3.7.1}/.gitignore +1 -0
- {typedal-3.6.0 → typedal-3.7.1}/CHANGELOG.md +17 -0
- {typedal-3.6.0 → typedal-3.7.1}/PKG-INFO +28 -2
- {typedal-3.6.0 → typedal-3.7.1}/README.md +24 -0
- {typedal-3.6.0 → typedal-3.7.1}/pyproject.toml +3 -1
- {typedal-3.6.0 → typedal-3.7.1}/src/typedal/__about__.py +1 -1
- {typedal-3.6.0 → typedal-3.7.1}/src/typedal/core.py +24 -7
- {typedal-3.6.0 → typedal-3.7.1}/src/typedal/helpers.py +30 -1
- {typedal-3.6.0 → typedal-3.7.1}/tests/test_helpers.py +32 -1
- typedal-3.6.0/htmlcov/.gitignore +0 -2
- typedal-3.6.0/htmlcov/class_index.html +0 -563
- typedal-3.6.0/htmlcov/coverage_html.js +0 -624
- typedal-3.6.0/htmlcov/coverage_html_cb_da166b87.js +0 -717
- typedal-3.6.0/htmlcov/d_0ccc93afd6526b6c___about___py.html +0 -105
- typedal-3.6.0/htmlcov/d_0ccc93afd6526b6c___init___py.html +0 -110
- typedal-3.6.0/htmlcov/d_0ccc93afd6526b6c_caching_py.html +0 -504
- typedal-3.6.0/htmlcov/d_0ccc93afd6526b6c_cli_py.html +0 -683
- typedal-3.6.0/htmlcov/d_0ccc93afd6526b6c_config_py.html +0 -457
- typedal-3.6.0/htmlcov/d_0ccc93afd6526b6c_core_py.html +0 -2905
- typedal-3.6.0/htmlcov/d_0ccc93afd6526b6c_fields_py.html +0 -339
- typedal-3.6.0/htmlcov/d_0ccc93afd6526b6c_for_py4web_py.html +0 -154
- typedal-3.6.0/htmlcov/d_0ccc93afd6526b6c_for_web2py_py.html +0 -169
- typedal-3.6.0/htmlcov/d_0ccc93afd6526b6c_helpers_py.html +0 -364
- typedal-3.6.0/htmlcov/d_0ccc93afd6526b6c_mixins_py.html +0 -269
- typedal-3.6.0/htmlcov/d_0ccc93afd6526b6c_types_py.html +0 -325
- typedal-3.6.0/htmlcov/d_0ccc93afd6526b6c_web2py_py4web_shared_py.html +0 -141
- typedal-3.6.0/htmlcov/d_18c616467159315a_as_json_py.html +0 -172
- typedal-3.6.0/htmlcov/favicon_32.png +0 -0
- typedal-3.6.0/htmlcov/favicon_32_cb_58284776.png +0 -0
- typedal-3.6.0/htmlcov/function_index.html +0 -2571
- typedal-3.6.0/htmlcov/index.html +0 -202
- typedal-3.6.0/htmlcov/keybd_closed.png +0 -0
- typedal-3.6.0/htmlcov/keybd_closed_cb_ce680311.png +0 -0
- typedal-3.6.0/htmlcov/keybd_open.png +0 -0
- typedal-3.6.0/htmlcov/status.json +0 -1
- typedal-3.6.0/htmlcov/style.css +0 -309
- typedal-3.6.0/htmlcov/style_cb_8e611ae1.css +0 -337
- typedal-3.6.0/htmlcov/z_0ccc93afd6526b6c___about___py.html +0 -105
- typedal-3.6.0/htmlcov/z_0ccc93afd6526b6c___init___py.html +0 -110
- typedal-3.6.0/htmlcov/z_0ccc93afd6526b6c_caching_py.html +0 -504
- typedal-3.6.0/htmlcov/z_0ccc93afd6526b6c_cli_py.html +0 -715
- typedal-3.6.0/htmlcov/z_0ccc93afd6526b6c_config_py.html +0 -457
- typedal-3.6.0/htmlcov/z_0ccc93afd6526b6c_core_py.html +0 -2971
- typedal-3.6.0/htmlcov/z_0ccc93afd6526b6c_fields_py.html +0 -339
- typedal-3.6.0/htmlcov/z_0ccc93afd6526b6c_for_py4web_py.html +0 -154
- typedal-3.6.0/htmlcov/z_0ccc93afd6526b6c_for_web2py_py.html +0 -169
- typedal-3.6.0/htmlcov/z_0ccc93afd6526b6c_helpers_py.html +0 -373
- typedal-3.6.0/htmlcov/z_0ccc93afd6526b6c_mixins_py.html +0 -269
- typedal-3.6.0/htmlcov/z_0ccc93afd6526b6c_types_py.html +0 -349
- typedal-3.6.0/htmlcov/z_0ccc93afd6526b6c_web2py_py4web_shared_py.html +0 -141
- typedal-3.6.0/htmlcov/z_18c616467159315a_as_json_py.html +0 -172
- {typedal-3.6.0 → typedal-3.7.1}/.github/workflows/su6.yml +0 -0
- {typedal-3.6.0 → typedal-3.7.1}/.readthedocs.yml +0 -0
- {typedal-3.6.0 → typedal-3.7.1}/coverage.svg +0 -0
- {typedal-3.6.0 → typedal-3.7.1}/docs/1_getting_started.md +0 -0
- {typedal-3.6.0 → typedal-3.7.1}/docs/2_defining_tables.md +0 -0
- {typedal-3.6.0 → typedal-3.7.1}/docs/3_building_queries.md +0 -0
- {typedal-3.6.0 → typedal-3.7.1}/docs/4_relationships.md +0 -0
- {typedal-3.6.0 → typedal-3.7.1}/docs/5_py4web.md +0 -0
- {typedal-3.6.0 → typedal-3.7.1}/docs/6_migrations.md +0 -0
- {typedal-3.6.0 → typedal-3.7.1}/docs/7_mixins.md +0 -0
- {typedal-3.6.0 → typedal-3.7.1}/docs/css/code_blocks.css +0 -0
- {typedal-3.6.0 → typedal-3.7.1}/docs/index.md +0 -0
- {typedal-3.6.0 → typedal-3.7.1}/docs/requirements.txt +0 -0
- {typedal-3.6.0 → typedal-3.7.1}/example_new.py +0 -0
- {typedal-3.6.0 → typedal-3.7.1}/example_old.py +0 -0
- {typedal-3.6.0 → typedal-3.7.1}/mkdocs.yml +0 -0
- {typedal-3.6.0 → typedal-3.7.1}/src/typedal/__init__.py +0 -0
- {typedal-3.6.0 → typedal-3.7.1}/src/typedal/caching.py +0 -0
- {typedal-3.6.0 → typedal-3.7.1}/src/typedal/cli.py +0 -0
- {typedal-3.6.0 → typedal-3.7.1}/src/typedal/config.py +0 -0
- {typedal-3.6.0 → typedal-3.7.1}/src/typedal/fields.py +0 -0
- {typedal-3.6.0 → typedal-3.7.1}/src/typedal/for_py4web.py +0 -0
- {typedal-3.6.0 → typedal-3.7.1}/src/typedal/for_web2py.py +0 -0
- {typedal-3.6.0 → typedal-3.7.1}/src/typedal/mixins.py +0 -0
- {typedal-3.6.0 → typedal-3.7.1}/src/typedal/py.typed +0 -0
- {typedal-3.6.0 → typedal-3.7.1}/src/typedal/serializers/as_json.py +0 -0
- {typedal-3.6.0 → typedal-3.7.1}/src/typedal/types.py +0 -0
- {typedal-3.6.0 → typedal-3.7.1}/src/typedal/web2py_py4web_shared.py +0 -0
- {typedal-3.6.0 → typedal-3.7.1}/tests/__init__.py +0 -0
- {typedal-3.6.0 → typedal-3.7.1}/tests/configs/simple.toml +0 -0
- {typedal-3.6.0 → typedal-3.7.1}/tests/configs/valid.env +0 -0
- {typedal-3.6.0 → typedal-3.7.1}/tests/configs/valid.toml +0 -0
- {typedal-3.6.0 → typedal-3.7.1}/tests/test_cli.py +0 -0
- {typedal-3.6.0 → typedal-3.7.1}/tests/test_config.py +0 -0
- {typedal-3.6.0 → typedal-3.7.1}/tests/test_docs_examples.py +0 -0
- {typedal-3.6.0 → typedal-3.7.1}/tests/test_json.py +0 -0
- {typedal-3.6.0 → typedal-3.7.1}/tests/test_main.py +0 -0
- {typedal-3.6.0 → typedal-3.7.1}/tests/test_mixins.py +0 -0
- {typedal-3.6.0 → typedal-3.7.1}/tests/test_mypy.py +0 -0
- {typedal-3.6.0 → typedal-3.7.1}/tests/test_orm.py +0 -0
- {typedal-3.6.0 → typedal-3.7.1}/tests/test_py4web.py +0 -0
- {typedal-3.6.0 → typedal-3.7.1}/tests/test_query_builder.py +0 -0
- {typedal-3.6.0 → typedal-3.7.1}/tests/test_relationships.py +0 -0
- {typedal-3.6.0 → typedal-3.7.1}/tests/test_row.py +0 -0
- {typedal-3.6.0 → typedal-3.7.1}/tests/test_stats.py +0 -0
- {typedal-3.6.0 → typedal-3.7.1}/tests/test_table.py +0 -0
- {typedal-3.6.0 → typedal-3.7.1}/tests/test_web2py.py +0 -0
- {typedal-3.6.0 → typedal-3.7.1}/tests/test_xx_others.py +0 -0
- {typedal-3.6.0 → typedal-3.7.1}/tests/timings.py +0 -0
|
@@ -2,6 +2,23 @@
|
|
|
2
2
|
|
|
3
3
|
<!--next-version-placeholder-->
|
|
4
4
|
|
|
5
|
+
## v3.7.1 (2024-10-09)
|
|
6
|
+
|
|
7
|
+
### Fix
|
|
8
|
+
|
|
9
|
+
* Prepare for python 3.13 (-> cgi dependency, changes in forward reference evaluation); except psycopg2 ([`bbcca8f`](https://github.com/trialandsuccess/TypeDAL/commit/bbcca8f7a5d2f8a6ddc8caf3a1b05fde3ed2fdd2))
|
|
10
|
+
* Require legacy-cgi for python 3.13+ ([`7ba9489`](https://github.com/trialandsuccess/TypeDAL/commit/7ba94898cde600008a350e718783a4d0dbc05e45))
|
|
11
|
+
|
|
12
|
+
### Documentation
|
|
13
|
+
|
|
14
|
+
* **readme:** Include `from typedal.helpers import get_db` in example ([`8853052`](https://github.com/trialandsuccess/TypeDAL/commit/8853052575b4576945901eb87da94bf709e99526))
|
|
15
|
+
|
|
16
|
+
## v3.7.0 (2024-08-17)
|
|
17
|
+
|
|
18
|
+
### Feature
|
|
19
|
+
|
|
20
|
+
* Add get_db, get_table, get_field helpers to get pydal objects back from typedal ([`2363e9d`](https://github.com/trialandsuccess/TypeDAL/commit/2363e9d3f15eb4500a0d5bc8354bf0326161bd1e))
|
|
21
|
+
|
|
5
22
|
## v3.6.0 (2024-08-05)
|
|
6
23
|
|
|
7
24
|
### Feature
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: TypeDAL
|
|
3
|
-
Version: 3.
|
|
3
|
+
Version: 3.7.1
|
|
4
4
|
Summary: Typing support for PyDAL
|
|
5
5
|
Project-URL: Documentation, https://typedal.readthedocs.io/
|
|
6
6
|
Project-URL: Issues, https://github.com/trialandsuccess/TypeDAL/issues
|
|
@@ -12,16 +12,18 @@ Classifier: Programming Language :: Python
|
|
|
12
12
|
Classifier: Programming Language :: Python :: 3.10
|
|
13
13
|
Classifier: Programming Language :: Python :: 3.11
|
|
14
14
|
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
15
16
|
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
16
17
|
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
17
18
|
Requires-Python: >=3.10
|
|
18
19
|
Requires-Dist: configurable-json
|
|
19
20
|
Requires-Dist: configuraptor>=1.26.2
|
|
20
21
|
Requires-Dist: dill
|
|
22
|
+
Requires-Dist: legacy-cgi; python_version >= '3.13'
|
|
21
23
|
Requires-Dist: pydal
|
|
22
24
|
Requires-Dist: python-slugify
|
|
23
25
|
Provides-Extra: all
|
|
24
|
-
Requires-Dist: edwh-migrate>=0.8.0; extra == 'all'
|
|
26
|
+
Requires-Dist: edwh-migrate[full]>=0.8.0; extra == 'all'
|
|
25
27
|
Requires-Dist: py4web; extra == 'all'
|
|
26
28
|
Requires-Dist: pydal2sql[all]>=1.2.0; extra == 'all'
|
|
27
29
|
Requires-Dist: questionary; extra == 'all'
|
|
@@ -301,6 +303,30 @@ row: TableName = db.table_name(id=1)
|
|
|
301
303
|
|
|
302
304
|
See [2. Defining Tables](https://typedal.readthedocs.io/en/stable/2_defining_tables/)
|
|
303
305
|
|
|
306
|
+
### Helpers
|
|
307
|
+
|
|
308
|
+
TypeDAL provides some utility functions to interact with the underlying pyDAL objects:
|
|
309
|
+
|
|
310
|
+
- **`get_db(TableName)`**:
|
|
311
|
+
Retrieve the DAL instance associated with a given TypedTable or pyDAL Table.
|
|
312
|
+
|
|
313
|
+
- **`get_table(TableName)`**:
|
|
314
|
+
Access the original PyDAL Table from a TypedTable instance (`db.table_name`).
|
|
315
|
+
|
|
316
|
+
- **`get_field(TableName.fieldname)`**:
|
|
317
|
+
Get the pyDAL Field from a TypedField. This ensures compatibility when interacting directly with PyDAL.
|
|
318
|
+
|
|
319
|
+
These helpers are useful for scenarios where direct access to the PyDAL objects is needed while still using TypeDAL.
|
|
320
|
+
An example of this is when you need to do a `db.commit()` but you can't import `db` directly:
|
|
321
|
+
|
|
322
|
+
```python
|
|
323
|
+
from typedal.helpers import get_db #, get_table, get_field
|
|
324
|
+
|
|
325
|
+
MyTable.insert(...)
|
|
326
|
+
db = get_db(MyTable)
|
|
327
|
+
db.commit() # this is usually done automatically but sometimes you want to manually commit.
|
|
328
|
+
```
|
|
329
|
+
|
|
304
330
|
## Caveats
|
|
305
331
|
|
|
306
332
|
- This package depends heavily on the current implementation of annotations (which are computed when the class is
|
|
@@ -247,6 +247,30 @@ row: TableName = db.table_name(id=1)
|
|
|
247
247
|
|
|
248
248
|
See [2. Defining Tables](https://typedal.readthedocs.io/en/stable/2_defining_tables/)
|
|
249
249
|
|
|
250
|
+
### Helpers
|
|
251
|
+
|
|
252
|
+
TypeDAL provides some utility functions to interact with the underlying pyDAL objects:
|
|
253
|
+
|
|
254
|
+
- **`get_db(TableName)`**:
|
|
255
|
+
Retrieve the DAL instance associated with a given TypedTable or pyDAL Table.
|
|
256
|
+
|
|
257
|
+
- **`get_table(TableName)`**:
|
|
258
|
+
Access the original PyDAL Table from a TypedTable instance (`db.table_name`).
|
|
259
|
+
|
|
260
|
+
- **`get_field(TableName.fieldname)`**:
|
|
261
|
+
Get the pyDAL Field from a TypedField. This ensures compatibility when interacting directly with PyDAL.
|
|
262
|
+
|
|
263
|
+
These helpers are useful for scenarios where direct access to the PyDAL objects is needed while still using TypeDAL.
|
|
264
|
+
An example of this is when you need to do a `db.commit()` but you can't import `db` directly:
|
|
265
|
+
|
|
266
|
+
```python
|
|
267
|
+
from typedal.helpers import get_db #, get_table, get_field
|
|
268
|
+
|
|
269
|
+
MyTable.insert(...)
|
|
270
|
+
db = get_db(MyTable)
|
|
271
|
+
db.commit() # this is usually done automatically but sometimes you want to manually commit.
|
|
272
|
+
```
|
|
273
|
+
|
|
250
274
|
## Caveats
|
|
251
275
|
|
|
252
276
|
- This package depends heavily on the current implementation of annotations (which are computed when the class is
|
|
@@ -19,6 +19,7 @@ classifiers = [
|
|
|
19
19
|
"Programming Language :: Python :: 3.10",
|
|
20
20
|
"Programming Language :: Python :: 3.11",
|
|
21
21
|
"Programming Language :: Python :: 3.12",
|
|
22
|
+
"Programming Language :: Python :: 3.13",
|
|
22
23
|
"Programming Language :: Python :: Implementation :: CPython",
|
|
23
24
|
"Programming Language :: Python :: Implementation :: PyPy",
|
|
24
25
|
]
|
|
@@ -28,6 +29,7 @@ dependencies = [
|
|
|
28
29
|
"configuraptor >= 1.26.2", # config
|
|
29
30
|
"Configurable-JSON", # json dumping
|
|
30
31
|
"python-slugify",
|
|
32
|
+
"legacy-cgi; python_version >= '3.13'"
|
|
31
33
|
]
|
|
32
34
|
|
|
33
35
|
[project.optional-dependencies]
|
|
@@ -49,7 +51,7 @@ all = [
|
|
|
49
51
|
"typer",
|
|
50
52
|
"tabulate",
|
|
51
53
|
"pydal2sql[all]>=1.2.0",
|
|
52
|
-
"edwh-migrate>=0.8.0",
|
|
54
|
+
"edwh-migrate[full]>=0.8.0",
|
|
53
55
|
"questionary",
|
|
54
56
|
"tomlkit",
|
|
55
57
|
]
|
|
@@ -8,6 +8,7 @@ import datetime as dt
|
|
|
8
8
|
import inspect
|
|
9
9
|
import json
|
|
10
10
|
import math
|
|
11
|
+
import sys
|
|
11
12
|
import types
|
|
12
13
|
import typing
|
|
13
14
|
import warnings
|
|
@@ -339,6 +340,22 @@ def to_relationship(
|
|
|
339
340
|
return Relationship(typing.cast(type[TypedTable], field), condition, typing.cast(JOIN_OPTIONS, join))
|
|
340
341
|
|
|
341
342
|
|
|
343
|
+
def evaluate_forward_reference(fw_ref: typing.ForwardRef) -> type:
|
|
344
|
+
"""
|
|
345
|
+
Extract the original type from a forward reference string.
|
|
346
|
+
"""
|
|
347
|
+
kwargs = dict(
|
|
348
|
+
localns=locals(),
|
|
349
|
+
globalns=globals(),
|
|
350
|
+
recursive_guard=frozenset(),
|
|
351
|
+
)
|
|
352
|
+
if sys.version_info >= (3, 13):
|
|
353
|
+
# required since 3.13 and not supported before
|
|
354
|
+
kwargs["type_params"] = ()
|
|
355
|
+
|
|
356
|
+
return fw_ref._evaluate(**kwargs) # type: ignore
|
|
357
|
+
|
|
358
|
+
|
|
342
359
|
class TypeDAL(pydal.DAL): # type: ignore
|
|
343
360
|
"""
|
|
344
361
|
Drop-in replacement for pyDAL with layer to convert class-based table definitions to classical pydal define_tables.
|
|
@@ -465,6 +482,7 @@ class TypeDAL(pydal.DAL): # type: ignore
|
|
|
465
482
|
# when __future__.annotations is implemented, cls.__annotations__ will not work anymore as below.
|
|
466
483
|
# proper way to handle this would be (but gives error right now due to Table implementing magic methods):
|
|
467
484
|
# typing.get_type_hints(cls, globalns=None, localns=None)
|
|
485
|
+
# -> ERR e.g. `pytest -svxk cli` -> name 'BestFriend' is not defined
|
|
468
486
|
|
|
469
487
|
# dirty way (with evil eval):
|
|
470
488
|
# [eval(v) for k, v in cls.__annotations__.items()]
|
|
@@ -674,9 +692,8 @@ class TypeDAL(pydal.DAL): # type: ignore
|
|
|
674
692
|
|
|
675
693
|
if isinstance(ftype, str):
|
|
676
694
|
# extract type from string
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
)
|
|
695
|
+
fw_ref: typing.ForwardRef = typing.get_args(Type[ftype])[0]
|
|
696
|
+
ftype = evaluate_forward_reference(fw_ref)
|
|
680
697
|
|
|
681
698
|
if mapping := BASIC_MAPPINGS.get(ftype):
|
|
682
699
|
# basi types
|
|
@@ -1144,7 +1161,7 @@ class TableMeta(type):
|
|
|
1144
1161
|
"""
|
|
1145
1162
|
Add a before insert hook.
|
|
1146
1163
|
"""
|
|
1147
|
-
cls._before_insert.append(fn)
|
|
1164
|
+
cls._before_insert.append(fn)
|
|
1148
1165
|
return cls
|
|
1149
1166
|
|
|
1150
1167
|
def after_insert(
|
|
@@ -1157,7 +1174,7 @@ class TableMeta(type):
|
|
|
1157
1174
|
"""
|
|
1158
1175
|
Add an after insert hook.
|
|
1159
1176
|
"""
|
|
1160
|
-
cls._after_insert.append(fn)
|
|
1177
|
+
cls._after_insert.append(fn)
|
|
1161
1178
|
return cls
|
|
1162
1179
|
|
|
1163
1180
|
def before_update(
|
|
@@ -1167,7 +1184,7 @@ class TableMeta(type):
|
|
|
1167
1184
|
"""
|
|
1168
1185
|
Add a before update hook.
|
|
1169
1186
|
"""
|
|
1170
|
-
cls._before_update.append(fn)
|
|
1187
|
+
cls._before_update.append(fn)
|
|
1171
1188
|
return cls
|
|
1172
1189
|
|
|
1173
1190
|
def after_update(
|
|
@@ -1177,7 +1194,7 @@ class TableMeta(type):
|
|
|
1177
1194
|
"""
|
|
1178
1195
|
Add an after update hook.
|
|
1179
1196
|
"""
|
|
1180
|
-
cls._after_update.append(fn)
|
|
1197
|
+
cls._after_update.append(fn)
|
|
1181
1198
|
return cls
|
|
1182
1199
|
|
|
1183
1200
|
def before_delete(cls: Type[T_MetaInstance], fn: typing.Callable[[Set], Optional[bool]]) -> Type[T_MetaInstance]:
|
|
@@ -10,7 +10,12 @@ import typing
|
|
|
10
10
|
from collections import ChainMap
|
|
11
11
|
from typing import Any
|
|
12
12
|
|
|
13
|
-
from
|
|
13
|
+
from pydal import DAL
|
|
14
|
+
|
|
15
|
+
from .types import AnyDict, Field, Table
|
|
16
|
+
|
|
17
|
+
if typing.TYPE_CHECKING:
|
|
18
|
+
from . import TypeDAL, TypedField, TypedTable # noqa: F401
|
|
14
19
|
|
|
15
20
|
T = typing.TypeVar("T")
|
|
16
21
|
|
|
@@ -274,3 +279,27 @@ def utcnow() -> dt.datetime:
|
|
|
274
279
|
"""
|
|
275
280
|
# return dt.datetime.now(dt.UTC)
|
|
276
281
|
return dt.datetime.now(dt.timezone.utc)
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
def get_db(table: "TypedTable | Table") -> "DAL":
|
|
285
|
+
"""
|
|
286
|
+
Get the underlying DAL instance for a pydal or typedal table.
|
|
287
|
+
"""
|
|
288
|
+
return typing.cast("DAL", table._db)
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
def get_table(table: "TypedTable | Table") -> "Table":
|
|
292
|
+
"""
|
|
293
|
+
Get the underlying pydal table for a typedal table.
|
|
294
|
+
"""
|
|
295
|
+
return typing.cast("Table", table._table)
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
def get_field(field: "TypedField[typing.Any] | Field") -> "Field":
|
|
299
|
+
"""
|
|
300
|
+
Get the underlying pydal field from a typedal field.
|
|
301
|
+
"""
|
|
302
|
+
return typing.cast(
|
|
303
|
+
"Field",
|
|
304
|
+
field, # Table.field already is a Field, but cast to make sure the editor knows this too.
|
|
305
|
+
)
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import typing
|
|
2
2
|
from datetime import datetime, timedelta
|
|
3
3
|
|
|
4
|
+
import pydal
|
|
4
5
|
import pytest
|
|
6
|
+
from pydal import DAL
|
|
5
7
|
|
|
6
8
|
from src.typedal.caching import get_expire
|
|
7
9
|
from src.typedal.helpers import (
|
|
@@ -16,8 +18,10 @@ from src.typedal.helpers import (
|
|
|
16
18
|
mktable,
|
|
17
19
|
origin_is_subclass,
|
|
18
20
|
to_snake,
|
|
19
|
-
unwrap_type,
|
|
21
|
+
unwrap_type, get_db, get_table, get_field,
|
|
20
22
|
)
|
|
23
|
+
from typedal import TypeDAL, TypedTable
|
|
24
|
+
from typedal.types import Field
|
|
21
25
|
|
|
22
26
|
|
|
23
27
|
def test_is_union():
|
|
@@ -175,3 +179,30 @@ def test_match_strings():
|
|
|
175
179
|
string_list = ["file1.txt", "file2.jpg", "file3.txt", "file4.png"]
|
|
176
180
|
expected_matches = []
|
|
177
181
|
assert sorted(match_strings(patterns, string_list)) == sorted(expected_matches)
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
database = TypeDAL("sqlite:memory")
|
|
185
|
+
assert database._db_uid
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
@database.define()
|
|
189
|
+
class TestGetFunctions(TypedTable):
|
|
190
|
+
string: str
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
def test_get_functions():
|
|
194
|
+
db = get_db(TestGetFunctions)
|
|
195
|
+
assert isinstance(db, DAL)
|
|
196
|
+
assert db._db_uid == database._db_uid
|
|
197
|
+
db = get_db(db.test_get_functions)
|
|
198
|
+
assert db._db_uid == database._db_uid
|
|
199
|
+
table = get_table(TestGetFunctions)
|
|
200
|
+
assert hasattr(table, "string")
|
|
201
|
+
assert issubclass(TestGetFunctions, TypedTable)
|
|
202
|
+
assert isinstance(table, pydal.objects.Table)
|
|
203
|
+
assert not isinstance(table, TypedTable)
|
|
204
|
+
field = get_field(TestGetFunctions.string)
|
|
205
|
+
print(
|
|
206
|
+
type(field)
|
|
207
|
+
)
|
|
208
|
+
assert isinstance(field, Field)
|
typedal-3.6.0/htmlcov/.gitignore
DELETED