TypeDAL 3.15.5__tar.gz → 3.16.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.

Files changed (58) hide show
  1. {typedal-3.15.5 → typedal-3.16.1}/CHANGELOG.md +12 -0
  2. {typedal-3.15.5 → typedal-3.16.1}/PKG-INFO +1 -1
  3. {typedal-3.15.5 → typedal-3.16.1}/src/typedal/__about__.py +1 -1
  4. {typedal-3.15.5 → typedal-3.16.1}/src/typedal/core.py +40 -0
  5. {typedal-3.15.5 → typedal-3.16.1}/tests/test_main.py +31 -2
  6. {typedal-3.15.5 → typedal-3.16.1}/.github/workflows/su6.yml +0 -0
  7. {typedal-3.15.5 → typedal-3.16.1}/.gitignore +0 -0
  8. {typedal-3.15.5 → typedal-3.16.1}/.readthedocs.yml +0 -0
  9. {typedal-3.15.5 → typedal-3.16.1}/README.md +0 -0
  10. {typedal-3.15.5 → typedal-3.16.1}/coverage.svg +0 -0
  11. {typedal-3.15.5 → typedal-3.16.1}/docs/1_getting_started.md +0 -0
  12. {typedal-3.15.5 → typedal-3.16.1}/docs/2_defining_tables.md +0 -0
  13. {typedal-3.15.5 → typedal-3.16.1}/docs/3_building_queries.md +0 -0
  14. {typedal-3.15.5 → typedal-3.16.1}/docs/4_relationships.md +0 -0
  15. {typedal-3.15.5 → typedal-3.16.1}/docs/5_py4web.md +0 -0
  16. {typedal-3.15.5 → typedal-3.16.1}/docs/6_migrations.md +0 -0
  17. {typedal-3.15.5 → typedal-3.16.1}/docs/7_mixins.md +0 -0
  18. {typedal-3.15.5 → typedal-3.16.1}/docs/css/code_blocks.css +0 -0
  19. {typedal-3.15.5 → typedal-3.16.1}/docs/index.md +0 -0
  20. {typedal-3.15.5 → typedal-3.16.1}/docs/requirements.txt +0 -0
  21. {typedal-3.15.5 → typedal-3.16.1}/example_new.py +0 -0
  22. {typedal-3.15.5 → typedal-3.16.1}/example_old.py +0 -0
  23. {typedal-3.15.5 → typedal-3.16.1}/mkdocs.yml +0 -0
  24. {typedal-3.15.5 → typedal-3.16.1}/pyproject.toml +0 -0
  25. {typedal-3.15.5 → typedal-3.16.1}/src/typedal/__init__.py +0 -0
  26. {typedal-3.15.5 → typedal-3.16.1}/src/typedal/caching.py +0 -0
  27. {typedal-3.15.5 → typedal-3.16.1}/src/typedal/cli.py +0 -0
  28. {typedal-3.15.5 → typedal-3.16.1}/src/typedal/config.py +0 -0
  29. {typedal-3.15.5 → typedal-3.16.1}/src/typedal/fields.py +0 -0
  30. {typedal-3.15.5 → typedal-3.16.1}/src/typedal/for_py4web.py +0 -0
  31. {typedal-3.15.5 → typedal-3.16.1}/src/typedal/for_web2py.py +0 -0
  32. {typedal-3.15.5 → typedal-3.16.1}/src/typedal/helpers.py +0 -0
  33. {typedal-3.15.5 → typedal-3.16.1}/src/typedal/mixins.py +0 -0
  34. {typedal-3.15.5 → typedal-3.16.1}/src/typedal/py.typed +0 -0
  35. {typedal-3.15.5 → typedal-3.16.1}/src/typedal/serializers/as_json.py +0 -0
  36. {typedal-3.15.5 → typedal-3.16.1}/src/typedal/types.py +0 -0
  37. {typedal-3.15.5 → typedal-3.16.1}/src/typedal/web2py_py4web_shared.py +0 -0
  38. {typedal-3.15.5 → typedal-3.16.1}/tests/__init__.py +0 -0
  39. {typedal-3.15.5 → typedal-3.16.1}/tests/configs/simple.toml +0 -0
  40. {typedal-3.15.5 → typedal-3.16.1}/tests/configs/valid.env +0 -0
  41. {typedal-3.15.5 → typedal-3.16.1}/tests/configs/valid.toml +0 -0
  42. {typedal-3.15.5 → typedal-3.16.1}/tests/test_cli.py +0 -0
  43. {typedal-3.15.5 → typedal-3.16.1}/tests/test_config.py +0 -0
  44. {typedal-3.15.5 → typedal-3.16.1}/tests/test_docs_examples.py +0 -0
  45. {typedal-3.15.5 → typedal-3.16.1}/tests/test_helpers.py +0 -0
  46. {typedal-3.15.5 → typedal-3.16.1}/tests/test_json.py +0 -0
  47. {typedal-3.15.5 → typedal-3.16.1}/tests/test_mixins.py +0 -0
  48. {typedal-3.15.5 → typedal-3.16.1}/tests/test_mypy.py +0 -0
  49. {typedal-3.15.5 → typedal-3.16.1}/tests/test_orm.py +0 -0
  50. {typedal-3.15.5 → typedal-3.16.1}/tests/test_py4web.py +0 -0
  51. {typedal-3.15.5 → typedal-3.16.1}/tests/test_query_builder.py +0 -0
  52. {typedal-3.15.5 → typedal-3.16.1}/tests/test_relationships.py +0 -0
  53. {typedal-3.15.5 → typedal-3.16.1}/tests/test_row.py +0 -0
  54. {typedal-3.15.5 → typedal-3.16.1}/tests/test_stats.py +0 -0
  55. {typedal-3.15.5 → typedal-3.16.1}/tests/test_table.py +0 -0
  56. {typedal-3.15.5 → typedal-3.16.1}/tests/test_web2py.py +0 -0
  57. {typedal-3.15.5 → typedal-3.16.1}/tests/test_xx_others.py +0 -0
  58. {typedal-3.15.5 → typedal-3.16.1}/tests/timings.py +0 -0
@@ -2,6 +2,18 @@
2
2
 
3
3
  <!--next-version-placeholder-->
4
4
 
5
+ ## v3.16.1 (2025-09-01)
6
+
7
+ ### Fix
8
+
9
+ * Make `reorder_fields` take fields via * args so you don't have to wrap it in [] ([`625ed31`](https://github.com/trialandsuccess/TypeDAL/commit/625ed3182826725e03e04e9154012ee2e482761e))
10
+
11
+ ## v3.16.0 (2025-09-01)
12
+
13
+ ### Feature
14
+
15
+ * Allow reordering table fields via `Table.reorder_fields(...)` ([`79c2c3e`](https://github.com/trialandsuccess/TypeDAL/commit/79c2c3eaf8b44919800e4c12026ab54a2678d141))
16
+
5
17
  ## v3.15.5 (2025-08-29)
6
18
 
7
19
  ### Fix
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: TypeDAL
3
- Version: 3.15.5
3
+ Version: 3.16.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
@@ -5,4 +5,4 @@ This file contains the Version info for this package.
5
5
  # SPDX-FileCopyrightText: 2023-present Robin van der Noord <robinvandernoord@gmail.com>
6
6
  #
7
7
  # SPDX-License-Identifier: MIT
8
- __version__ = "3.15.5"
8
+ __version__ = "3.16.1"
@@ -2,6 +2,8 @@
2
2
  Core functionality of TypeDAL.
3
3
  """
4
4
 
5
+ from __future__ import annotations
6
+
5
7
  import contextlib
6
8
  import csv
7
9
  import datetime as dt
@@ -826,6 +828,31 @@ P = typing.ParamSpec("P")
826
828
  R = typing.TypeVar("R")
827
829
 
828
830
 
831
+ def reorder_fields(
832
+ table: pydal.objects.Table, fields: typing.Iterable[str | Field | TypedField], keep_others: bool = True
833
+ ) -> None:
834
+ """
835
+ Reorder fields of a pydal table.
836
+
837
+ Args:
838
+ table: The pydal table object (e.g., db.mytable).
839
+ fields: List of field names (str) or Field objects in desired order.
840
+ keep_others (bool):
841
+ - True (default): keep other fields at the end, in their original order.
842
+ - False: remove other fields (only keep what's specified).
843
+ """
844
+ # Normalize input to field names
845
+ desired = [f.name if isinstance(f, (TypedField, Field, pydal.objects.Field)) else str(f) for f in fields]
846
+
847
+ new_order = [f for f in desired if f in table._fields]
848
+
849
+ if keep_others:
850
+ # Start with desired fields, then append the rest
851
+ new_order.extend(f for f in table._fields if f not in desired)
852
+
853
+ table._fields = new_order
854
+
855
+
829
856
  class TableMeta(type):
830
857
  """
831
858
  This metaclass contains functionality on table classes, that doesn't exist on its instances.
@@ -1367,6 +1394,19 @@ class TableMeta(type):
1367
1394
  """
1368
1395
  return cls._hook_once(cls._after_delete, fn)
1369
1396
 
1397
+ def reorder_fields(cls, *fields: str | Field | TypedField, keep_others: bool = True):
1398
+ """
1399
+ Reorder fields of a typedal table.
1400
+
1401
+ Args:
1402
+ fields: List of field names (str) or Field objects in desired order.
1403
+ keep_others (bool):
1404
+ - True (default): keep other fields at the end, in their original order.
1405
+ - False: remove other fields (only keep what's specified).
1406
+ """
1407
+
1408
+ return reorder_fields(cls._table, fields, keep_others=keep_others)
1409
+
1370
1410
 
1371
1411
  class TypedField(Expression, typing.Generic[T_Value]): # pragma: no cover
1372
1412
  """
@@ -115,11 +115,19 @@ def test_mixed_defines(capsys):
115
115
  ## insert normal
116
116
  db.old_syntax.insert(name="First", age=99, location="Norway", relation=db.relation(id=1))
117
117
  db.first_new_syntax.insert(
118
- name="First", age=99, location="Norway", old_relation=db.relation(id=1), tags=["first", "second"]
118
+ name="First",
119
+ age=99,
120
+ location="Norway",
121
+ old_relation=db.relation(id=1),
122
+ tags=["first", "second"],
119
123
  )
120
124
  # equals
121
125
  FirstNewSyntax.insert(
122
- name="First", age=99, location="Norway", old_relation=db.relation(id=1), tags=["first", "second"]
126
+ name="First",
127
+ age=99,
128
+ location="Norway",
129
+ old_relation=db.relation(id=1),
130
+ tags=["first", "second"],
123
131
  )
124
132
  # similar
125
133
  SecondNewSyntax.insert(
@@ -570,3 +578,24 @@ def test_try():
570
578
 
571
579
  with pytest.warns(RuntimeWarning):
572
580
  assert db.try_define(SomeTableToRetry, verbose=True)
581
+
582
+
583
+ def test_reorder_fields():
584
+ @db.define()
585
+ class Base(TypedTable):
586
+ gid: str
587
+
588
+ @db.define()
589
+ class Sub(Base):
590
+ name: str
591
+
592
+ # default order is kinda cursed due to MRO:
593
+ assert list(Sub) == [Sub.id, Sub.name, Sub.gid]
594
+
595
+ # 'name' should come last:
596
+ Sub.reorder_fields(Sub.id, Sub.gid)
597
+ assert list(Sub) == [Sub.id, Sub.gid, Sub.name]
598
+
599
+ # 'name' should be dropped:
600
+ Sub.reorder_fields(Sub.id, Sub.gid, keep_others=False)
601
+ assert list(Sub) == [Sub.id, Sub.gid]
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
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
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes