piccolo 1.27.1__py3-none-any.whl → 1.29.0__py3-none-any.whl

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.
Files changed (132) hide show
  1. piccolo/__init__.py +1 -1
  2. piccolo/apps/app/commands/new.py +3 -3
  3. piccolo/apps/asgi/commands/new.py +2 -3
  4. piccolo/apps/asgi/commands/templates/app/_blacksheep_app.py.jinja +57 -29
  5. piccolo/apps/asgi/commands/templates/app/_esmerald_app.py.jinja +48 -21
  6. piccolo/apps/asgi/commands/templates/app/_falcon_app.py.jinja +63 -8
  7. piccolo/apps/asgi/commands/templates/app/_fastapi_app.py.jinja +51 -24
  8. piccolo/apps/asgi/commands/templates/app/_litestar_app.py.jinja +34 -10
  9. piccolo/apps/asgi/commands/templates/app/_quart_app.py.jinja +38 -15
  10. piccolo/apps/asgi/commands/templates/app/_sanic_app.py.jinja +34 -11
  11. piccolo/apps/fixtures/commands/dump.py +8 -8
  12. piccolo/apps/fixtures/commands/load.py +5 -5
  13. piccolo/apps/fixtures/commands/shared.py +9 -9
  14. piccolo/apps/migrations/auto/diffable_table.py +12 -12
  15. piccolo/apps/migrations/auto/migration_manager.py +59 -66
  16. piccolo/apps/migrations/auto/operations.py +14 -14
  17. piccolo/apps/migrations/auto/schema_differ.py +35 -34
  18. piccolo/apps/migrations/auto/schema_snapshot.py +3 -4
  19. piccolo/apps/migrations/auto/serialisation.py +27 -24
  20. piccolo/apps/migrations/auto/serialisation_legacy.py +2 -2
  21. piccolo/apps/migrations/commands/backwards.py +1 -2
  22. piccolo/apps/migrations/commands/base.py +12 -12
  23. piccolo/apps/migrations/commands/check.py +2 -3
  24. piccolo/apps/migrations/commands/clean.py +3 -3
  25. piccolo/apps/migrations/commands/forwards.py +1 -2
  26. piccolo/apps/migrations/commands/new.py +6 -6
  27. piccolo/apps/migrations/tables.py +3 -3
  28. piccolo/apps/playground/commands/run.py +72 -13
  29. piccolo/apps/schema/commands/generate.py +49 -49
  30. piccolo/apps/schema/commands/graph.py +5 -5
  31. piccolo/apps/shell/commands/run.py +1 -2
  32. piccolo/apps/sql_shell/commands/run.py +4 -4
  33. piccolo/apps/tester/commands/run.py +3 -3
  34. piccolo/apps/user/commands/change_permissions.py +6 -6
  35. piccolo/apps/user/commands/create.py +7 -7
  36. piccolo/apps/user/commands/list.py +2 -2
  37. piccolo/apps/user/tables.py +8 -8
  38. piccolo/columns/base.py +84 -52
  39. piccolo/columns/choices.py +2 -2
  40. piccolo/columns/column_types.py +299 -177
  41. piccolo/columns/combination.py +15 -12
  42. piccolo/columns/defaults/base.py +4 -4
  43. piccolo/columns/defaults/date.py +4 -3
  44. piccolo/columns/defaults/interval.py +4 -3
  45. piccolo/columns/defaults/time.py +4 -3
  46. piccolo/columns/defaults/timestamp.py +4 -3
  47. piccolo/columns/defaults/timestamptz.py +4 -3
  48. piccolo/columns/defaults/uuid.py +3 -2
  49. piccolo/columns/m2m.py +28 -35
  50. piccolo/columns/readable.py +4 -3
  51. piccolo/columns/reference.py +9 -9
  52. piccolo/conf/apps.py +53 -54
  53. piccolo/custom_types.py +28 -6
  54. piccolo/engine/base.py +14 -14
  55. piccolo/engine/cockroach.py +5 -4
  56. piccolo/engine/finder.py +2 -2
  57. piccolo/engine/postgres.py +20 -19
  58. piccolo/engine/sqlite.py +23 -22
  59. piccolo/query/base.py +30 -29
  60. piccolo/query/functions/__init__.py +12 -0
  61. piccolo/query/functions/aggregate.py +4 -3
  62. piccolo/query/functions/array.py +151 -0
  63. piccolo/query/functions/base.py +3 -3
  64. piccolo/query/functions/datetime.py +22 -22
  65. piccolo/query/functions/string.py +4 -4
  66. piccolo/query/functions/type_conversion.py +30 -15
  67. piccolo/query/methods/alter.py +47 -46
  68. piccolo/query/methods/count.py +11 -10
  69. piccolo/query/methods/create.py +6 -5
  70. piccolo/query/methods/create_index.py +9 -8
  71. piccolo/query/methods/delete.py +7 -6
  72. piccolo/query/methods/drop_index.py +7 -6
  73. piccolo/query/methods/exists.py +6 -5
  74. piccolo/query/methods/indexes.py +4 -4
  75. piccolo/query/methods/insert.py +21 -14
  76. piccolo/query/methods/objects.py +60 -50
  77. piccolo/query/methods/raw.py +7 -6
  78. piccolo/query/methods/refresh.py +8 -7
  79. piccolo/query/methods/select.py +56 -49
  80. piccolo/query/methods/table_exists.py +5 -5
  81. piccolo/query/methods/update.py +8 -7
  82. piccolo/query/mixins.py +56 -61
  83. piccolo/query/operators/json.py +11 -11
  84. piccolo/query/proxy.py +8 -9
  85. piccolo/querystring.py +14 -15
  86. piccolo/schema.py +10 -10
  87. piccolo/table.py +105 -98
  88. piccolo/table_reflection.py +9 -9
  89. piccolo/testing/model_builder.py +16 -13
  90. piccolo/testing/random_builder.py +14 -2
  91. piccolo/testing/test_case.py +4 -4
  92. piccolo/utils/dictionary.py +3 -3
  93. piccolo/utils/encoding.py +5 -5
  94. piccolo/utils/lazy_loader.py +3 -3
  95. piccolo/utils/list.py +7 -8
  96. piccolo/utils/objects.py +4 -6
  97. piccolo/utils/pydantic.py +21 -24
  98. piccolo/utils/sql_values.py +3 -3
  99. piccolo/utils/sync.py +4 -3
  100. piccolo/utils/warnings.py +1 -2
  101. {piccolo-1.27.1.dist-info → piccolo-1.29.0.dist-info}/METADATA +1 -1
  102. {piccolo-1.27.1.dist-info → piccolo-1.29.0.dist-info}/RECORD +132 -131
  103. tests/apps/fixtures/commands/test_dump_load.py +1 -2
  104. tests/apps/migrations/auto/integration/test_migrations.py +32 -7
  105. tests/apps/migrations/auto/test_migration_manager.py +2 -2
  106. tests/apps/migrations/auto/test_schema_differ.py +22 -23
  107. tests/apps/migrations/commands/test_forwards_backwards.py +3 -3
  108. tests/columns/m2m/base.py +20 -49
  109. tests/columns/test_array.py +176 -10
  110. tests/columns/test_boolean.py +2 -4
  111. tests/columns/test_combination.py +29 -1
  112. tests/columns/test_db_column_name.py +2 -2
  113. tests/engine/test_extra_nodes.py +2 -2
  114. tests/engine/test_pool.py +3 -3
  115. tests/engine/test_transaction.py +4 -4
  116. tests/query/test_freeze.py +4 -4
  117. tests/table/instance/test_get_related.py +2 -2
  118. tests/table/test_alter.py +4 -4
  119. tests/table/test_indexes.py +1 -2
  120. tests/table/test_metaclass.py +7 -3
  121. tests/table/test_refresh.py +2 -2
  122. tests/table/test_select.py +58 -0
  123. tests/table/test_str.py +30 -22
  124. tests/table/test_update.py +18 -3
  125. tests/testing/test_model_builder.py +1 -2
  126. tests/testing/test_random_builder.py +5 -0
  127. tests/utils/test_pydantic.py +152 -134
  128. tests/utils/test_table_reflection.py +1 -2
  129. {piccolo-1.27.1.dist-info → piccolo-1.29.0.dist-info}/WHEEL +0 -0
  130. {piccolo-1.27.1.dist-info → piccolo-1.29.0.dist-info}/entry_points.txt +0 -0
  131. {piccolo-1.27.1.dist-info → piccolo-1.29.0.dist-info}/licenses/LICENSE +0 -0
  132. {piccolo-1.27.1.dist-info → piccolo-1.29.0.dist-info}/top_level.txt +0 -0
@@ -1,5 +1,5 @@
1
1
  import decimal
2
- import typing as t
2
+ from typing import Optional, cast
3
3
  from unittest import TestCase
4
4
 
5
5
  import pydantic
@@ -29,10 +29,10 @@ from piccolo.utils.pydantic import create_pydantic_model
29
29
 
30
30
  class TestVarcharColumn(TestCase):
31
31
  def test_varchar_length(self):
32
- class Director(Table):
32
+ class Manager(Table):
33
33
  name = Varchar(length=10)
34
34
 
35
- pydantic_model = create_pydantic_model(table=Director)
35
+ pydantic_model = create_pydantic_model(table=Manager)
36
36
 
37
37
  with self.assertRaises(ValidationError):
38
38
  pydantic_model(name="This is a really long name")
@@ -42,10 +42,10 @@ class TestVarcharColumn(TestCase):
42
42
 
43
43
  class TestEmailColumn(TestCase):
44
44
  def test_email(self):
45
- class Director(Table):
45
+ class Manager(Table):
46
46
  email = Email()
47
47
 
48
- pydantic_model = create_pydantic_model(table=Director)
48
+ pydantic_model = create_pydantic_model(table=Manager)
49
49
 
50
50
  self.assertEqual(
51
51
  pydantic_model.model_json_schema()["properties"]["email"]["anyOf"][
@@ -67,28 +67,28 @@ class TestNumericColumn(TestCase):
67
67
  """
68
68
 
69
69
  def test_numeric_digits(self):
70
- class Movie(Table):
71
- box_office = Numeric(digits=(5, 1))
70
+ class Band(Table):
71
+ royalties = Numeric(digits=(5, 1))
72
72
 
73
- pydantic_model = create_pydantic_model(table=Movie)
73
+ pydantic_model = create_pydantic_model(table=Band)
74
74
 
75
75
  with self.assertRaises(ValidationError):
76
76
  # This should fail as there are too much numbers after the decimal
77
77
  # point
78
- pydantic_model(box_office=decimal.Decimal("1.11"))
78
+ pydantic_model(royalties=decimal.Decimal("1.11"))
79
79
 
80
80
  with self.assertRaises(ValidationError):
81
81
  # This should fail as there are too much numbers in total
82
- pydantic_model(box_office=decimal.Decimal("11111.1"))
82
+ pydantic_model(royalties=decimal.Decimal("11111.1"))
83
83
 
84
- pydantic_model(box_office=decimal.Decimal("1.0"))
84
+ pydantic_model(royalties=decimal.Decimal("1.0"))
85
85
 
86
86
  def test_numeric_without_digits(self):
87
- class Movie(Table):
88
- box_office = Numeric()
87
+ class Band(Table):
88
+ royalties = Numeric()
89
89
 
90
90
  try:
91
- create_pydantic_model(table=Movie)
91
+ create_pydantic_model(table=Band)
92
92
  except TypeError:
93
93
  self.fail(
94
94
  "Creating numeric field without"
@@ -138,7 +138,7 @@ class TestArrayColumn(TestCase):
138
138
 
139
139
  self.assertEqual(
140
140
  pydantic_model.model_fields["members"].annotation,
141
- t.List[t.List[pydantic.constr(max_length=255)]],
141
+ list[list[pydantic.constr(max_length=255)]],
142
142
  )
143
143
 
144
144
  # Should not raise a validation error:
@@ -297,13 +297,13 @@ class TestColumnHelpText(TestCase):
297
297
  def test_column_help_text_present(self):
298
298
  help_text = "In millions of US dollars."
299
299
 
300
- class Movie(Table):
301
- box_office = Numeric(digits=(5, 1), help_text=help_text)
300
+ class Band(Table):
301
+ royalties = Numeric(digits=(5, 1), help_text=help_text)
302
302
 
303
- pydantic_model = create_pydantic_model(table=Movie)
303
+ pydantic_model = create_pydantic_model(table=Band)
304
304
 
305
305
  self.assertEqual(
306
- pydantic_model.model_json_schema()["properties"]["box_office"][
306
+ pydantic_model.model_json_schema()["properties"]["royalties"][
307
307
  "extra"
308
308
  ]["help_text"],
309
309
  help_text,
@@ -317,12 +317,12 @@ class TestTableHelpText(TestCase):
317
317
  """
318
318
 
319
319
  def test_table_help_text_present(self):
320
- help_text = "Movies which were released in cinemas."
320
+ help_text = "Bands playing concerts."
321
321
 
322
- class Movie(Table, help_text=help_text):
322
+ class Band(Table, help_text=help_text):
323
323
  name = Varchar()
324
324
 
325
- pydantic_model = create_pydantic_model(table=Movie)
325
+ pydantic_model = create_pydantic_model(table=Band)
326
326
 
327
327
  self.assertEqual(
328
328
  pydantic_model.model_json_schema()["extra"]["help_text"],
@@ -332,10 +332,10 @@ class TestTableHelpText(TestCase):
332
332
 
333
333
  class TestUniqueColumn(TestCase):
334
334
  def test_unique_column_true(self):
335
- class Director(Table):
335
+ class Manager(Table):
336
336
  name = Varchar(unique=True)
337
337
 
338
- pydantic_model = create_pydantic_model(table=Director)
338
+ pydantic_model = create_pydantic_model(table=Manager)
339
339
 
340
340
  self.assertEqual(
341
341
  pydantic_model.model_json_schema()["properties"]["name"]["extra"][
@@ -345,10 +345,10 @@ class TestUniqueColumn(TestCase):
345
345
  )
346
346
 
347
347
  def test_unique_column_false(self):
348
- class Director(Table):
348
+ class Manager(Table):
349
349
  name = Varchar()
350
350
 
351
- pydantic_model = create_pydantic_model(table=Director)
351
+ pydantic_model = create_pydantic_model(table=Manager)
352
352
 
353
353
  self.assertEqual(
354
354
  pydantic_model.model_json_schema()["properties"]["name"]["extra"][
@@ -360,48 +360,66 @@ class TestUniqueColumn(TestCase):
360
360
 
361
361
  class TestJSONColumn(TestCase):
362
362
  def test_default(self):
363
- class Movie(Table):
364
- meta = JSON()
365
- meta_b = JSONB()
363
+ class Studio(Table):
364
+ facilities = JSON()
365
+ facilities_b = JSONB()
366
366
 
367
- pydantic_model = create_pydantic_model(table=Movie)
367
+ pydantic_model = create_pydantic_model(table=Studio)
368
368
 
369
- json_string = '{"code": 12345}'
369
+ json_string = '{"guitar_amps": 6}'
370
370
 
371
- model_instance = pydantic_model(meta=json_string, meta_b=json_string)
372
- self.assertEqual(model_instance.meta, json_string) # type: ignore
373
- self.assertEqual(model_instance.meta_b, json_string) # type: ignore
371
+ model_instance = pydantic_model(
372
+ facilities=json_string, facilities_b=json_string
373
+ )
374
+ self.assertEqual(
375
+ model_instance.facilities,
376
+ json_string,
377
+ )
378
+ self.assertEqual(
379
+ model_instance.facilities_b,
380
+ json_string,
381
+ )
374
382
 
375
383
  def test_deserialize_json(self):
376
- class Movie(Table):
377
- meta = JSON()
378
- meta_b = JSONB()
384
+ class Studio(Table):
385
+ facilities = JSON()
386
+ facilities_b = JSONB()
379
387
 
380
388
  pydantic_model = create_pydantic_model(
381
- table=Movie, deserialize_json=True
389
+ table=Studio, deserialize_json=True
382
390
  )
383
391
 
384
- json_string = '{"code": 12345}'
385
- output = {"code": 12345}
392
+ json_string = '{"guitar_amps": 6}'
393
+ output = {"guitar_amps": 6}
386
394
 
387
- model_instance = pydantic_model(meta=json_string, meta_b=json_string)
388
- self.assertEqual(model_instance.meta, output) # type: ignore
389
- self.assertEqual(model_instance.meta_b, output) # type: ignore
395
+ model_instance = pydantic_model(
396
+ facilities=json_string, facilities_b=json_string
397
+ )
398
+ self.assertEqual(
399
+ model_instance.facilities,
400
+ output,
401
+ )
402
+ self.assertEqual(
403
+ model_instance.facilities_b,
404
+ output,
405
+ )
390
406
 
391
407
  def test_validation(self):
392
- class Movie(Table):
393
- meta = JSON()
394
- meta_b = JSONB()
408
+ class Studio(Table):
409
+ facilities = JSON()
410
+ facilities_b = JSONB()
395
411
 
396
412
  for deserialize_json in (True, False):
397
413
  pydantic_model = create_pydantic_model(
398
- table=Movie, deserialize_json=deserialize_json
414
+ table=Studio, deserialize_json=deserialize_json
399
415
  )
400
416
 
401
417
  json_string = "error"
402
418
 
403
419
  with self.assertRaises(pydantic.ValidationError):
404
- pydantic_model(meta=json_string, meta_b=json_string)
420
+ pydantic_model(
421
+ facilities=json_string, facilities_b=json_string
422
+ )
405
423
 
406
424
  def test_json_widget(self):
407
425
  """
@@ -409,112 +427,112 @@ class TestJSONColumn(TestCase):
409
427
  special widget in Piccolo Admin.
410
428
  """
411
429
 
412
- class Movie(Table):
413
- features = JSON()
430
+ class Studio(Table):
431
+ facilities = JSON()
414
432
 
415
- pydantic_model = create_pydantic_model(table=Movie)
433
+ pydantic_model = create_pydantic_model(table=Studio)
416
434
 
417
435
  self.assertEqual(
418
- pydantic_model.model_json_schema()["properties"]["features"][
436
+ pydantic_model.model_json_schema()["properties"]["facilities"][
419
437
  "extra"
420
438
  ]["widget"],
421
439
  "json",
422
440
  )
423
441
 
424
442
  def test_null_value(self):
425
- class Movie(Table):
426
- meta = JSON(null=True)
427
- meta_b = JSONB(null=True)
443
+ class Studio(Table):
444
+ facilities = JSON(null=True)
445
+ facilities_b = JSONB(null=True)
428
446
 
429
- pydantic_model = create_pydantic_model(table=Movie)
430
- movie = pydantic_model(meta=None, meta_b=None)
447
+ pydantic_model = create_pydantic_model(table=Studio)
448
+ movie = pydantic_model(facilities=None, facilities_b=None)
431
449
 
432
- self.assertIsNone(movie.meta) # type: ignore
433
- self.assertIsNone(movie.meta_b) # type: ignore
450
+ self.assertIsNone(movie.facilities)
451
+ self.assertIsNone(movie.facilities_b)
434
452
 
435
453
 
436
454
  class TestExcludeColumns(TestCase):
437
455
  def test_all(self):
438
- class Computer(Table):
439
- CPU = Varchar()
440
- GPU = Varchar()
456
+ class Band(Table):
457
+ name = Varchar()
458
+ bio = Text()
441
459
 
442
- pydantic_model = create_pydantic_model(Computer, exclude_columns=())
460
+ pydantic_model = create_pydantic_model(Band, exclude_columns=())
443
461
 
444
462
  properties = pydantic_model.model_json_schema()["properties"]
445
- self.assertIsInstance(properties["GPU"], dict)
446
- self.assertIsInstance(properties["CPU"], dict)
463
+ self.assertIsInstance(properties["name"], dict)
464
+ self.assertIsInstance(properties["bio"], dict)
447
465
 
448
466
  def test_exclude(self):
449
- class Computer(Table):
450
- CPU = Varchar()
451
- GPU = Varchar()
467
+ class Band(Table):
468
+ name = Varchar()
469
+ album = Varchar()
452
470
 
453
471
  pydantic_model = create_pydantic_model(
454
- Computer,
455
- exclude_columns=(Computer.CPU,),
472
+ Band,
473
+ exclude_columns=(Band.name,),
456
474
  )
457
475
 
458
476
  properties = pydantic_model.model_json_schema()["properties"]
459
- self.assertIsInstance(properties.get("GPU"), dict)
460
- self.assertIsNone(properties.get("CPU"))
477
+ self.assertIsInstance(properties.get("album"), dict)
478
+ self.assertIsNone(properties.get("dict"))
461
479
 
462
480
  def test_exclude_all_manually(self):
463
- class Computer(Table):
464
- GPU = Varchar()
465
- CPU = Varchar()
481
+ class Band(Table):
482
+ name = Varchar()
483
+ album = Varchar()
466
484
 
467
485
  pydantic_model = create_pydantic_model(
468
- Computer,
469
- exclude_columns=(Computer.GPU, Computer.CPU),
486
+ Band,
487
+ exclude_columns=(Band.name, Band.album),
470
488
  )
471
489
 
472
490
  self.assertEqual(pydantic_model.model_json_schema()["properties"], {})
473
491
 
474
492
  def test_exclude_all_meta(self):
475
- class Computer(Table):
476
- GPU = Varchar()
477
- CPU = Varchar()
493
+ class Band(Table):
494
+ name = Varchar()
495
+ album = Varchar()
478
496
 
479
497
  pydantic_model = create_pydantic_model(
480
- Computer,
481
- exclude_columns=tuple(Computer._meta.columns),
498
+ Band,
499
+ exclude_columns=tuple(Band._meta.columns),
482
500
  )
483
501
 
484
502
  self.assertEqual(pydantic_model.model_json_schema()["properties"], {})
485
503
 
486
504
  def test_invalid_column_str(self):
487
- class Computer(Table):
488
- CPU = Varchar()
489
- GPU = Varchar()
505
+ class Band(Table):
506
+ name = Varchar()
507
+ album = Varchar()
490
508
 
491
509
  with self.assertRaises(ValueError):
492
510
  create_pydantic_model(
493
- Computer,
494
- exclude_columns=("CPU",), # type: ignore
511
+ Band,
512
+ exclude_columns=("album",),
495
513
  )
496
514
 
497
515
  def test_invalid_column_different_table(self):
498
- class Computer(Table):
499
- CPU = Varchar()
500
- GPU = Varchar()
516
+ class Band(Table):
517
+ name = Varchar()
518
+ album = Varchar()
501
519
 
502
- class Computer2(Table):
503
- SSD = Varchar()
520
+ class Band2(Table):
521
+ photo = Varchar()
504
522
 
505
523
  with self.assertRaises(ValueError):
506
- create_pydantic_model(Computer, exclude_columns=(Computer2.SSD,))
524
+ create_pydantic_model(Band, exclude_columns=(Band2.photo,))
507
525
 
508
526
  def test_invalid_column_different_table_same_type(self):
509
- class Computer(Table):
510
- CPU = Varchar()
511
- GPU = Varchar()
527
+ class Band(Table):
528
+ name = Varchar()
529
+ album = Varchar()
512
530
 
513
- class Computer2(Table):
514
- CPU = Varchar()
531
+ class Band2(Table):
532
+ name = Varchar()
515
533
 
516
534
  with self.assertRaises(ValueError):
517
- create_pydantic_model(Computer, exclude_columns=(Computer2.CPU,))
535
+ create_pydantic_model(Band, exclude_columns=(Band2.name,))
518
536
 
519
537
  def test_exclude_nested(self):
520
538
  class Manager(Table):
@@ -630,8 +648,8 @@ class TestNestedModel(TestCase):
630
648
 
631
649
  #######################################################################
632
650
 
633
- ManagerModel = t.cast(
634
- t.Type[pydantic.BaseModel],
651
+ ManagerModel = cast(
652
+ type[pydantic.BaseModel],
635
653
  BandModel.model_fields["manager"].annotation,
636
654
  )
637
655
  self.assertTrue(issubclass(ManagerModel, pydantic.BaseModel))
@@ -641,8 +659,8 @@ class TestNestedModel(TestCase):
641
659
 
642
660
  #######################################################################
643
661
 
644
- CountryModel = t.cast(
645
- t.Type[pydantic.BaseModel],
662
+ CountryModel = cast(
663
+ type[pydantic.BaseModel],
646
664
  ManagerModel.model_fields["country"].annotation,
647
665
  )
648
666
  self.assertTrue(issubclass(CountryModel, pydantic.BaseModel))
@@ -681,8 +699,8 @@ class TestNestedModel(TestCase):
681
699
 
682
700
  BandModel = create_pydantic_model(table=Band, nested=(Band.manager,))
683
701
 
684
- ManagerModel = t.cast(
685
- t.Type[pydantic.BaseModel],
702
+ ManagerModel = cast(
703
+ type[pydantic.BaseModel],
686
704
  BandModel.model_fields["manager"].annotation,
687
705
  )
688
706
  self.assertTrue(issubclass(ManagerModel, pydantic.BaseModel))
@@ -694,7 +712,7 @@ class TestNestedModel(TestCase):
694
712
  AssistantManagerType = BandModel.model_fields[
695
713
  "assistant_manager"
696
714
  ].annotation
697
- self.assertIs(AssistantManagerType, t.Optional[int])
715
+ self.assertIs(AssistantManagerType, Optional[int])
698
716
 
699
717
  #######################################################################
700
718
  # Test two levels deep
@@ -703,8 +721,8 @@ class TestNestedModel(TestCase):
703
721
  table=Band, nested=(Band.manager._.country,)
704
722
  )
705
723
 
706
- ManagerModel = t.cast(
707
- t.Type[pydantic.BaseModel],
724
+ ManagerModel = cast(
725
+ type[pydantic.BaseModel],
708
726
  BandModel.model_fields["manager"].annotation,
709
727
  )
710
728
  self.assertTrue(issubclass(ManagerModel, pydantic.BaseModel))
@@ -713,14 +731,14 @@ class TestNestedModel(TestCase):
713
731
  )
714
732
  self.assertEqual(ManagerModel.__qualname__, "Band.manager")
715
733
 
716
- AssistantManagerType = t.cast(
717
- t.Type[pydantic.BaseModel],
734
+ AssistantManagerType = cast(
735
+ type[pydantic.BaseModel],
718
736
  BandModel.model_fields["assistant_manager"].annotation,
719
737
  )
720
- self.assertIs(AssistantManagerType, t.Optional[int])
738
+ self.assertIs(AssistantManagerType, Optional[int])
721
739
 
722
- CountryModel = t.cast(
723
- t.Type[pydantic.BaseModel],
740
+ CountryModel = cast(
741
+ type[pydantic.BaseModel],
724
742
  ManagerModel.model_fields["country"].annotation,
725
743
  )
726
744
  self.assertTrue(issubclass(CountryModel, pydantic.BaseModel))
@@ -737,10 +755,10 @@ class TestNestedModel(TestCase):
737
755
  )
738
756
 
739
757
  VenueModel = ConcertModel.model_fields["venue"].annotation
740
- self.assertIs(VenueModel, t.Optional[int])
758
+ self.assertIs(VenueModel, Optional[int])
741
759
 
742
- BandModel = t.cast(
743
- t.Type[pydantic.BaseModel],
760
+ BandModel = cast(
761
+ type[pydantic.BaseModel],
744
762
  ConcertModel.model_fields["band_1"].annotation,
745
763
  )
746
764
  self.assertTrue(issubclass(BandModel, pydantic.BaseModel))
@@ -750,8 +768,8 @@ class TestNestedModel(TestCase):
750
768
  )
751
769
  self.assertEqual(BandModel.__qualname__, "Concert.band_1")
752
770
 
753
- ManagerModel = t.cast(
754
- t.Type[pydantic.BaseModel],
771
+ ManagerModel = cast(
772
+ type[pydantic.BaseModel],
755
773
  BandModel.model_fields["manager"].annotation,
756
774
  )
757
775
  self.assertTrue(issubclass(ManagerModel, pydantic.BaseModel))
@@ -764,10 +782,10 @@ class TestNestedModel(TestCase):
764
782
  AssistantManagerType = BandModel.model_fields[
765
783
  "assistant_manager"
766
784
  ].annotation
767
- self.assertIs(AssistantManagerType, t.Optional[int])
785
+ self.assertIs(AssistantManagerType, Optional[int])
768
786
 
769
787
  CountryModel = ManagerModel.model_fields["country"].annotation
770
- self.assertIs(CountryModel, t.Optional[int])
788
+ self.assertIs(CountryModel, Optional[int])
771
789
 
772
790
  #######################################################################
773
791
  # Test with `model_name` arg
@@ -778,8 +796,8 @@ class TestNestedModel(TestCase):
778
796
  model_name="MyConcertModel",
779
797
  )
780
798
 
781
- BandModel = t.cast(
782
- t.Type[pydantic.BaseModel],
799
+ BandModel = cast(
800
+ type[pydantic.BaseModel],
783
801
  MyConcertModel.model_fields["band_1"].annotation,
784
802
  )
785
803
  self.assertEqual(BandModel.__qualname__, "MyConcertModel.band_1")
@@ -810,8 +828,8 @@ class TestNestedModel(TestCase):
810
828
  table=Band, nested=True, include_default_columns=True
811
829
  )
812
830
 
813
- ManagerModel = t.cast(
814
- t.Type[pydantic.BaseModel],
831
+ ManagerModel = cast(
832
+ type[pydantic.BaseModel],
815
833
  BandModel.model_fields["manager"].annotation,
816
834
  )
817
835
  self.assertTrue(issubclass(ManagerModel, pydantic.BaseModel))
@@ -820,8 +838,8 @@ class TestNestedModel(TestCase):
820
838
  ["id", "name", "country"],
821
839
  )
822
840
 
823
- CountryModel = t.cast(
824
- t.Type[pydantic.BaseModel],
841
+ CountryModel = cast(
842
+ type[pydantic.BaseModel],
825
843
  ManagerModel.model_fields["country"].annotation,
826
844
  )
827
845
  self.assertTrue(issubclass(CountryModel, pydantic.BaseModel))
@@ -855,27 +873,27 @@ class TestRecursionDepth(TestCase):
855
873
  table=Concert, nested=True, max_recursion_depth=2
856
874
  )
857
875
 
858
- VenueModel = t.cast(
859
- t.Type[pydantic.BaseModel],
876
+ VenueModel = cast(
877
+ type[pydantic.BaseModel],
860
878
  ConcertModel.model_fields["venue"].annotation,
861
879
  )
862
880
  self.assertTrue(issubclass(VenueModel, pydantic.BaseModel))
863
881
 
864
- BandModel = t.cast(
865
- t.Type[pydantic.BaseModel],
882
+ BandModel = cast(
883
+ type[pydantic.BaseModel],
866
884
  ConcertModel.model_fields["band"].annotation,
867
885
  )
868
886
  self.assertTrue(issubclass(BandModel, pydantic.BaseModel))
869
887
 
870
- ManagerModel = t.cast(
871
- t.Type[pydantic.BaseModel],
888
+ ManagerModel = cast(
889
+ type[pydantic.BaseModel],
872
890
  BandModel.model_fields["manager"].annotation,
873
891
  )
874
892
  self.assertTrue(issubclass(ManagerModel, pydantic.BaseModel))
875
893
 
876
894
  # We should have hit the recursion depth:
877
895
  CountryModel = ManagerModel.model_fields["country"].annotation
878
- self.assertIs(CountryModel, t.Optional[int])
896
+ self.assertIs(CountryModel, Optional[int])
879
897
 
880
898
 
881
899
  class TestDBColumnName(TestCase):
@@ -892,7 +910,7 @@ class TestDBColumnName(TestCase):
892
910
 
893
911
  model = BandModel(regrettable_column_name="test")
894
912
 
895
- self.assertEqual(model.name, "test") # type: ignore
913
+ self.assertEqual(model.name, "test")
896
914
 
897
915
 
898
916
  class TestJSONSchemaExtra(TestCase):
@@ -1,4 +1,3 @@
1
- import typing as t
2
1
  from unittest import TestCase
3
2
 
4
3
  from piccolo.columns import Varchar
@@ -22,7 +21,7 @@ class TestTableStorage(TestCase):
22
21
  table_class.alter().drop_table(if_exists=True).run_sync()
23
22
 
24
23
  def _compare_table_columns(
25
- self, table_1: t.Type[Table], table_2: t.Type[Table]
24
+ self, table_1: type[Table], table_2: type[Table]
26
25
  ):
27
26
  """
28
27
  Make sure that for each column in table_1, there is a corresponding