prefect-client 3.1.5__py3-none-any.whl → 3.1.6__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 (93) hide show
  1. prefect/__init__.py +3 -0
  2. prefect/_internal/compatibility/migration.py +1 -1
  3. prefect/_internal/concurrency/api.py +52 -52
  4. prefect/_internal/concurrency/calls.py +59 -35
  5. prefect/_internal/concurrency/cancellation.py +34 -18
  6. prefect/_internal/concurrency/event_loop.py +7 -6
  7. prefect/_internal/concurrency/threads.py +41 -33
  8. prefect/_internal/concurrency/waiters.py +28 -21
  9. prefect/_internal/pydantic/v1_schema.py +2 -2
  10. prefect/_internal/pydantic/v2_schema.py +10 -9
  11. prefect/_internal/schemas/bases.py +9 -7
  12. prefect/_internal/schemas/validators.py +2 -1
  13. prefect/_version.py +3 -3
  14. prefect/automations.py +53 -47
  15. prefect/blocks/abstract.py +12 -10
  16. prefect/blocks/core.py +4 -2
  17. prefect/cache_policies.py +11 -11
  18. prefect/client/__init__.py +3 -1
  19. prefect/client/base.py +36 -37
  20. prefect/client/cloud.py +26 -19
  21. prefect/client/collections.py +2 -2
  22. prefect/client/orchestration.py +342 -273
  23. prefect/client/schemas/__init__.py +24 -0
  24. prefect/client/schemas/actions.py +123 -116
  25. prefect/client/schemas/objects.py +110 -81
  26. prefect/client/schemas/responses.py +18 -18
  27. prefect/client/schemas/schedules.py +136 -93
  28. prefect/client/subscriptions.py +28 -14
  29. prefect/client/utilities.py +32 -36
  30. prefect/concurrency/asyncio.py +6 -9
  31. prefect/concurrency/sync.py +35 -5
  32. prefect/context.py +39 -31
  33. prefect/deployments/flow_runs.py +3 -5
  34. prefect/docker/__init__.py +1 -1
  35. prefect/events/schemas/events.py +25 -20
  36. prefect/events/utilities.py +1 -2
  37. prefect/filesystems.py +3 -3
  38. prefect/flow_engine.py +61 -21
  39. prefect/flow_runs.py +3 -3
  40. prefect/flows.py +214 -170
  41. prefect/logging/configuration.py +1 -1
  42. prefect/logging/highlighters.py +1 -2
  43. prefect/logging/loggers.py +30 -20
  44. prefect/main.py +17 -24
  45. prefect/runner/runner.py +43 -21
  46. prefect/runner/server.py +30 -32
  47. prefect/runner/submit.py +3 -6
  48. prefect/runner/utils.py +6 -6
  49. prefect/runtime/flow_run.py +7 -0
  50. prefect/settings/constants.py +2 -2
  51. prefect/settings/legacy.py +1 -1
  52. prefect/settings/models/server/events.py +10 -0
  53. prefect/task_engine.py +72 -19
  54. prefect/task_runners.py +2 -2
  55. prefect/tasks.py +46 -33
  56. prefect/telemetry/bootstrap.py +15 -2
  57. prefect/telemetry/run_telemetry.py +107 -0
  58. prefect/transactions.py +14 -14
  59. prefect/types/__init__.py +1 -4
  60. prefect/utilities/_engine.py +96 -0
  61. prefect/utilities/annotations.py +25 -18
  62. prefect/utilities/asyncutils.py +126 -140
  63. prefect/utilities/callables.py +87 -78
  64. prefect/utilities/collections.py +278 -117
  65. prefect/utilities/compat.py +13 -21
  66. prefect/utilities/context.py +6 -5
  67. prefect/utilities/dispatch.py +23 -12
  68. prefect/utilities/dockerutils.py +33 -32
  69. prefect/utilities/engine.py +126 -239
  70. prefect/utilities/filesystem.py +18 -15
  71. prefect/utilities/hashing.py +10 -11
  72. prefect/utilities/importtools.py +40 -27
  73. prefect/utilities/math.py +9 -5
  74. prefect/utilities/names.py +3 -3
  75. prefect/utilities/processutils.py +121 -57
  76. prefect/utilities/pydantic.py +41 -36
  77. prefect/utilities/render_swagger.py +22 -12
  78. prefect/utilities/schema_tools/__init__.py +2 -1
  79. prefect/utilities/schema_tools/hydration.py +50 -43
  80. prefect/utilities/schema_tools/validation.py +52 -42
  81. prefect/utilities/services.py +13 -12
  82. prefect/utilities/templating.py +45 -45
  83. prefect/utilities/text.py +2 -1
  84. prefect/utilities/timeout.py +4 -4
  85. prefect/utilities/urls.py +9 -4
  86. prefect/utilities/visualization.py +46 -24
  87. prefect/variables.py +9 -8
  88. prefect/workers/base.py +15 -8
  89. {prefect_client-3.1.5.dist-info → prefect_client-3.1.6.dist-info}/METADATA +4 -2
  90. {prefect_client-3.1.5.dist-info → prefect_client-3.1.6.dist-info}/RECORD +93 -91
  91. {prefect_client-3.1.5.dist-info → prefect_client-3.1.6.dist-info}/LICENSE +0 -0
  92. {prefect_client-3.1.5.dist-info → prefect_client-3.1.6.dist-info}/WHEEL +0 -0
  93. {prefect_client-3.1.5.dist-info → prefect_client-3.1.6.dist-info}/top_level.txt +0 -0
@@ -1,15 +1,16 @@
1
1
  import datetime
2
2
  import warnings
3
+ from collections.abc import Callable, Mapping
3
4
  from functools import partial
4
5
  from typing import (
5
6
  TYPE_CHECKING,
6
7
  Annotated,
7
8
  Any,
8
- Dict,
9
+ ClassVar,
9
10
  Generic,
10
- List,
11
11
  Optional,
12
12
  Union,
13
+ cast,
13
14
  overload,
14
15
  )
15
16
  from uuid import UUID, uuid4
@@ -23,13 +24,12 @@ from pydantic import (
23
24
  HttpUrl,
24
25
  IPvAnyNetwork,
25
26
  SerializationInfo,
27
+ SerializerFunctionWrapHandler,
26
28
  Tag,
27
29
  field_validator,
28
30
  model_serializer,
29
31
  model_validator,
30
32
  )
31
- from pydantic.functional_validators import ModelWrapValidatorHandler
32
- from pydantic_extra_types.pendulum_dt import DateTime
33
33
  from typing_extensions import Literal, Self, TypeVar
34
34
 
35
35
  from prefect._internal.compatibility import deprecated
@@ -64,8 +64,13 @@ from prefect.utilities.names import generate_slug
64
64
  from prefect.utilities.pydantic import handle_secret_render
65
65
 
66
66
  if TYPE_CHECKING:
67
+ from prefect.client.schemas.actions import StateCreate
67
68
  from prefect.results import BaseResult, ResultRecordMetadata
68
69
 
70
+ DateTime = pendulum.DateTime
71
+ else:
72
+ from pydantic_extra_types.pendulum_dt import DateTime
73
+
69
74
 
70
75
  R = TypeVar("R", default=Any)
71
76
 
@@ -180,7 +185,7 @@ class StateDetails(PrefectBaseModel):
180
185
  pause_timeout: Optional[DateTime] = None
181
186
  pause_reschedule: bool = False
182
187
  pause_key: Optional[str] = None
183
- run_input_keyset: Optional[Dict[str, str]] = None
188
+ run_input_keyset: Optional[dict[str, str]] = None
184
189
  refresh_cache: Optional[bool] = None
185
190
  retriable: Optional[bool] = None
186
191
  transition_id: Optional[UUID] = None
@@ -215,11 +220,21 @@ class State(ObjectBaseModel, Generic[R]):
215
220
  ] = Field(default=None)
216
221
 
217
222
  @overload
218
- def result(self: "State[R]", raise_on_failure: bool = True) -> R:
223
+ def result(
224
+ self: "State[R]",
225
+ raise_on_failure: Literal[True] = ...,
226
+ fetch: bool = ...,
227
+ retry_result_failure: bool = ...,
228
+ ) -> R:
219
229
  ...
220
230
 
221
231
  @overload
222
- def result(self: "State[R]", raise_on_failure: bool = False) -> Union[R, Exception]:
232
+ def result(
233
+ self: "State[R]",
234
+ raise_on_failure: Literal[False] = False,
235
+ fetch: bool = ...,
236
+ retry_result_failure: bool = ...,
237
+ ) -> Union[R, Exception]:
223
238
  ...
224
239
 
225
240
  @deprecated.deprecated_parameter(
@@ -311,7 +326,7 @@ class State(ObjectBaseModel, Generic[R]):
311
326
  retry_result_failure=retry_result_failure,
312
327
  )
313
328
 
314
- def to_state_create(self):
329
+ def to_state_create(self) -> "StateCreate":
315
330
  """
316
331
  Convert this state to a `StateCreate` type which can be used to set the state of
317
332
  a run in the API.
@@ -327,7 +342,7 @@ class State(ObjectBaseModel, Generic[R]):
327
342
  )
328
343
 
329
344
  if isinstance(self.data, BaseResult):
330
- data = self.data
345
+ data = cast(BaseResult[R], self.data)
331
346
  elif isinstance(self.data, ResultRecord) and should_persist_result():
332
347
  data = self.data.metadata
333
348
  else:
@@ -348,14 +363,14 @@ class State(ObjectBaseModel, Generic[R]):
348
363
  # validation check and an error will be raised after this function is called
349
364
  name = self.name
350
365
  if name is None and self.type:
351
- self.name = " ".join([v.capitalize() for v in self.type.value.split("_")])
366
+ self.name = " ".join([v.capitalize() for v in self.type.split("_")])
352
367
  return self
353
368
 
354
369
  @model_validator(mode="after")
355
370
  def default_scheduled_start_time(self) -> Self:
356
371
  if self.type == StateType.SCHEDULED:
357
372
  if not self.state_details.scheduled_time:
358
- self.state_details.scheduled_time = DateTime.now("utc")
373
+ self.state_details.scheduled_time = pendulum.DateTime.now("utc")
359
374
  return self
360
375
 
361
376
  @model_validator(mode="after")
@@ -395,17 +410,19 @@ class State(ObjectBaseModel, Generic[R]):
395
410
  return self.type == StateType.PAUSED
396
411
 
397
412
  def model_copy(
398
- self, *, update: Optional[Dict[str, Any]] = None, deep: bool = False
399
- ):
413
+ self, *, update: Optional[Mapping[str, Any]] = None, deep: bool = False
414
+ ) -> Self:
400
415
  """
401
416
  Copying API models should return an object that could be inserted into the
402
417
  database again. The 'timestamp' is reset using the default factory.
403
418
  """
404
- update = update or {}
405
- update.setdefault("timestamp", self.model_fields["timestamp"].get_default())
419
+ update = {
420
+ "timestamp": self.model_fields["timestamp"].get_default(),
421
+ **(update or {}),
422
+ }
406
423
  return super().model_copy(update=update, deep=deep)
407
424
 
408
- def fresh_copy(self, **kwargs) -> Self:
425
+ def fresh_copy(self, **kwargs: Any) -> Self:
409
426
  """
410
427
  Return a fresh copy of the state with a new ID.
411
428
  """
@@ -443,12 +460,14 @@ class State(ObjectBaseModel, Generic[R]):
443
460
  `MyCompletedState("my message", type=COMPLETED)`
444
461
  """
445
462
 
446
- display = []
463
+ display: list[str] = []
447
464
 
448
465
  if self.message:
449
466
  display.append(repr(self.message))
450
467
 
451
- if self.type.value.lower() != self.name.lower():
468
+ if TYPE_CHECKING:
469
+ assert self.name is not None
470
+ if self.type.lower() != self.name.lower():
452
471
  display.append(f"type={self.type.value}")
453
472
 
454
473
  return f"{self.name}({', '.join(display)})"
@@ -487,7 +506,7 @@ class FlowRunPolicy(PrefectBaseModel):
487
506
  retry_delay: Optional[int] = Field(
488
507
  default=None, description="The delay time between retries, in seconds."
489
508
  )
490
- pause_keys: Optional[set] = Field(
509
+ pause_keys: Optional[set[str]] = Field(
491
510
  default_factory=set, description="Tracks pauses this run has observed."
492
511
  )
493
512
  resuming: Optional[bool] = Field(
@@ -499,7 +518,7 @@ class FlowRunPolicy(PrefectBaseModel):
499
518
 
500
519
  @model_validator(mode="before")
501
520
  @classmethod
502
- def populate_deprecated_fields(cls, values: Any):
521
+ def populate_deprecated_fields(cls, values: Any) -> Any:
503
522
  if isinstance(values, dict):
504
523
  return set_run_policy_deprecated_fields(values)
505
524
  return values
@@ -536,7 +555,7 @@ class FlowRun(ObjectBaseModel):
536
555
  description="The version of the flow executed in this flow run.",
537
556
  examples=["1.0"],
538
557
  )
539
- parameters: Dict[str, Any] = Field(
558
+ parameters: dict[str, Any] = Field(
540
559
  default_factory=dict, description="Parameters for the flow run."
541
560
  )
542
561
  idempotency_key: Optional[str] = Field(
@@ -546,7 +565,7 @@ class FlowRun(ObjectBaseModel):
546
565
  " run is not created multiple times."
547
566
  ),
548
567
  )
549
- context: Dict[str, Any] = Field(
568
+ context: dict[str, Any] = Field(
550
569
  default_factory=dict,
551
570
  description="Additional context for the flow run.",
552
571
  examples=[{"my_var": "my_val"}],
@@ -554,12 +573,12 @@ class FlowRun(ObjectBaseModel):
554
573
  empirical_policy: FlowRunPolicy = Field(
555
574
  default_factory=FlowRunPolicy,
556
575
  )
557
- tags: List[str] = Field(
576
+ tags: list[str] = Field(
558
577
  default_factory=list,
559
578
  description="A list of tags on the flow run",
560
579
  examples=[["tag-1", "tag-2"]],
561
580
  )
562
- labels: KeyValueLabelsField
581
+ labels: KeyValueLabelsField = Field(default_factory=dict)
563
582
  parent_task_run_id: Optional[UUID] = Field(
564
583
  default=None,
565
584
  description=(
@@ -632,7 +651,7 @@ class FlowRun(ObjectBaseModel):
632
651
  description="The state of the flow run.",
633
652
  examples=["State(type=StateType.COMPLETED)"],
634
653
  )
635
- job_variables: Optional[dict] = Field(
654
+ job_variables: Optional[dict[str, Any]] = Field(
636
655
  default=None,
637
656
  description="Job variables for the flow run.",
638
657
  )
@@ -663,7 +682,7 @@ class FlowRun(ObjectBaseModel):
663
682
 
664
683
  @field_validator("name", mode="before")
665
684
  @classmethod
666
- def set_default_name(cls, name):
685
+ def set_default_name(cls, name: Optional[str]) -> str:
667
686
  return get_or_create_run_name(name)
668
687
 
669
688
 
@@ -687,7 +706,7 @@ class TaskRunPolicy(PrefectBaseModel):
687
706
  deprecated=True,
688
707
  )
689
708
  retries: Optional[int] = Field(default=None, description="The number of retries.")
690
- retry_delay: Union[None, int, List[int]] = Field(
709
+ retry_delay: Union[None, int, list[int]] = Field(
691
710
  default=None,
692
711
  description="A delay time or list of delay times between retries, in seconds.",
693
712
  )
@@ -710,18 +729,20 @@ class TaskRunPolicy(PrefectBaseModel):
710
729
  self.retries = self.max_retries
711
730
 
712
731
  if not self.retry_delay and self.retry_delay_seconds != 0:
713
- self.retry_delay = self.retry_delay_seconds
732
+ self.retry_delay = int(self.retry_delay_seconds)
714
733
 
715
734
  return self
716
735
 
717
736
  @field_validator("retry_delay")
718
737
  @classmethod
719
- def validate_configured_retry_delays(cls, v):
738
+ def validate_configured_retry_delays(
739
+ cls, v: Optional[list[float]]
740
+ ) -> Optional[list[float]]:
720
741
  return list_length_50_or_less(v)
721
742
 
722
743
  @field_validator("retry_jitter_factor")
723
744
  @classmethod
724
- def validate_jitter_factor(cls, v):
745
+ def validate_jitter_factor(cls, v: Optional[float]) -> Optional[float]:
725
746
  return validate_not_negative(v)
726
747
 
727
748
 
@@ -731,9 +752,11 @@ class TaskRunInput(PrefectBaseModel):
731
752
  could include, constants, parameters, or other task runs.
732
753
  """
733
754
 
734
- model_config = ConfigDict(frozen=True)
755
+ model_config: ClassVar[ConfigDict] = ConfigDict(frozen=True)
735
756
 
736
- input_type: str
757
+ if not TYPE_CHECKING:
758
+ # subclasses provide the concrete type for this field
759
+ input_type: str
737
760
 
738
761
 
739
762
  class TaskRunResult(TaskRunInput):
@@ -791,16 +814,16 @@ class TaskRun(ObjectBaseModel):
791
814
  empirical_policy: TaskRunPolicy = Field(
792
815
  default_factory=TaskRunPolicy,
793
816
  )
794
- tags: List[str] = Field(
817
+ tags: list[str] = Field(
795
818
  default_factory=list,
796
819
  description="A list of tags for the task run.",
797
820
  examples=[["tag-1", "tag-2"]],
798
821
  )
799
- labels: KeyValueLabelsField
822
+ labels: KeyValueLabelsField = Field(default_factory=dict)
800
823
  state_id: Optional[UUID] = Field(
801
824
  default=None, description="The id of the current task run state."
802
825
  )
803
- task_inputs: Dict[str, List[Union[TaskRunResult, Parameter, Constant]]] = Field(
826
+ task_inputs: dict[str, list[Union[TaskRunResult, Parameter, Constant]]] = Field(
804
827
  default_factory=dict,
805
828
  description=(
806
829
  "Tracks the source of inputs to a task run. Used for internal bookkeeping. "
@@ -865,7 +888,7 @@ class TaskRun(ObjectBaseModel):
865
888
 
866
889
  @field_validator("name", mode="before")
867
890
  @classmethod
868
- def set_default_name(cls, name):
891
+ def set_default_name(cls, name: Optional[str]) -> Name:
869
892
  return get_or_create_run_name(name)
870
893
 
871
894
 
@@ -883,7 +906,7 @@ class Workspace(PrefectBaseModel):
883
906
  workspace_name: str = Field(..., description="The workspace name.")
884
907
  workspace_description: str = Field(..., description="Description of the workspace.")
885
908
  workspace_handle: str = Field(..., description="The workspace's unique handle.")
886
- model_config = ConfigDict(extra="ignore")
909
+ model_config: ClassVar[ConfigDict] = ConfigDict(extra="ignore")
887
910
 
888
911
  @property
889
912
  def handle(self) -> str:
@@ -912,7 +935,7 @@ class Workspace(PrefectBaseModel):
912
935
  f"/workspace/{self.workspace_id}"
913
936
  )
914
937
 
915
- def __hash__(self):
938
+ def __hash__(self) -> int:
916
939
  return hash(self.handle)
917
940
 
918
941
 
@@ -935,7 +958,7 @@ class IPAllowlist(PrefectBaseModel):
935
958
  Expected payload for an IP allowlist from the Prefect Cloud API.
936
959
  """
937
960
 
938
- entries: List[IPAllowlistEntry]
961
+ entries: list[IPAllowlistEntry]
939
962
 
940
963
 
941
964
  class IPAllowlistMyAccessResponse(PrefectBaseModel):
@@ -973,14 +996,14 @@ class BlockSchema(ObjectBaseModel):
973
996
  """A representation of a block schema."""
974
997
 
975
998
  checksum: str = Field(default=..., description="The block schema's unique checksum")
976
- fields: Dict[str, Any] = Field(
999
+ fields: dict[str, Any] = Field(
977
1000
  default_factory=dict, description="The block schema's field schema"
978
1001
  )
979
1002
  block_type_id: Optional[UUID] = Field(default=..., description="A block type ID")
980
1003
  block_type: Optional[BlockType] = Field(
981
1004
  default=None, description="The associated block type"
982
1005
  )
983
- capabilities: List[str] = Field(
1006
+ capabilities: list[str] = Field(
984
1007
  default_factory=list,
985
1008
  description="A list of Block capabilities",
986
1009
  )
@@ -999,7 +1022,7 @@ class BlockDocument(ObjectBaseModel):
999
1022
  "The block document's name. Not required for anonymous block documents."
1000
1023
  ),
1001
1024
  )
1002
- data: Dict[str, Any] = Field(
1025
+ data: dict[str, Any] = Field(
1003
1026
  default_factory=dict, description="The block document's data"
1004
1027
  )
1005
1028
  block_schema_id: UUID = Field(default=..., description="A block schema ID")
@@ -1011,7 +1034,7 @@ class BlockDocument(ObjectBaseModel):
1011
1034
  block_type: Optional[BlockType] = Field(
1012
1035
  default=None, description="The associated block type"
1013
1036
  )
1014
- block_document_references: Dict[str, Dict[str, Any]] = Field(
1037
+ block_document_references: dict[str, dict[str, Any]] = Field(
1015
1038
  default_factory=dict, description="Record of the block document's references"
1016
1039
  )
1017
1040
  is_anonymous: bool = Field(
@@ -1026,13 +1049,15 @@ class BlockDocument(ObjectBaseModel):
1026
1049
 
1027
1050
  @model_validator(mode="before")
1028
1051
  @classmethod
1029
- def validate_name_is_present_if_not_anonymous(cls, values):
1052
+ def validate_name_is_present_if_not_anonymous(
1053
+ cls, values: dict[str, Any]
1054
+ ) -> dict[str, Any]:
1030
1055
  return validate_name_present_on_nonanonymous_blocks(values)
1031
1056
 
1032
1057
  @model_serializer(mode="wrap")
1033
1058
  def serialize_data(
1034
- self, handler: ModelWrapValidatorHandler, info: SerializationInfo
1035
- ):
1059
+ self, handler: SerializerFunctionWrapHandler, info: SerializationInfo
1060
+ ) -> Any:
1036
1061
  self.data = visit_collection(
1037
1062
  self.data,
1038
1063
  visit_fn=partial(handle_secret_render, context=info.context or {}),
@@ -1047,7 +1072,7 @@ class Flow(ObjectBaseModel):
1047
1072
  name: Name = Field(
1048
1073
  default=..., description="The name of the flow", examples=["my-flow"]
1049
1074
  )
1050
- tags: List[str] = Field(
1075
+ tags: list[str] = Field(
1051
1076
  default_factory=list,
1052
1077
  description="A list of flow tags",
1053
1078
  examples=[["tag-1", "tag-2"]],
@@ -1091,22 +1116,22 @@ class Deployment(ObjectBaseModel):
1091
1116
  concurrency_limit: Optional[int] = Field(
1092
1117
  default=None, description="The concurrency limit for the deployment."
1093
1118
  )
1094
- schedules: List[DeploymentSchedule] = Field(
1119
+ schedules: list[DeploymentSchedule] = Field(
1095
1120
  default_factory=list, description="A list of schedules for the deployment."
1096
1121
  )
1097
- job_variables: Dict[str, Any] = Field(
1122
+ job_variables: dict[str, Any] = Field(
1098
1123
  default_factory=dict,
1099
1124
  description="Overrides to apply to flow run infrastructure at runtime.",
1100
1125
  )
1101
- parameters: Dict[str, Any] = Field(
1126
+ parameters: dict[str, Any] = Field(
1102
1127
  default_factory=dict,
1103
1128
  description="Parameters for flow runs scheduled by the deployment.",
1104
1129
  )
1105
- pull_steps: Optional[List[dict]] = Field(
1130
+ pull_steps: Optional[list[dict[str, Any]]] = Field(
1106
1131
  default=None,
1107
1132
  description="Pull steps for cloning and running this deployment.",
1108
1133
  )
1109
- tags: List[str] = Field(
1134
+ tags: list[str] = Field(
1110
1135
  default_factory=list,
1111
1136
  description="A list of tags for the deployment",
1112
1137
  examples=[["tag-1", "tag-2"]],
@@ -1123,7 +1148,7 @@ class Deployment(ObjectBaseModel):
1123
1148
  default=None,
1124
1149
  description="The last time the deployment was polled for status updates.",
1125
1150
  )
1126
- parameter_openapi_schema: Optional[Dict[str, Any]] = Field(
1151
+ parameter_openapi_schema: Optional[dict[str, Any]] = Field(
1127
1152
  default=None,
1128
1153
  description="The parameter schema of the flow, including defaults.",
1129
1154
  )
@@ -1177,7 +1202,7 @@ class ConcurrencyLimit(ObjectBaseModel):
1177
1202
  default=..., description="A tag the concurrency limit is applied to."
1178
1203
  )
1179
1204
  concurrency_limit: int = Field(default=..., description="The concurrency limit.")
1180
- active_slots: List[UUID] = Field(
1205
+ active_slots: list[UUID] = Field(
1181
1206
  default_factory=list,
1182
1207
  description="A list of active run ids using a concurrency slot",
1183
1208
  )
@@ -1224,7 +1249,7 @@ class BlockDocumentReference(ObjectBaseModel):
1224
1249
 
1225
1250
  @model_validator(mode="before")
1226
1251
  @classmethod
1227
- def validate_parent_and_ref_are_different(cls, values):
1252
+ def validate_parent_and_ref_are_different(cls, values: Any) -> Any:
1228
1253
  if isinstance(values, dict):
1229
1254
  return validate_parent_and_ref_diff(values)
1230
1255
  return values
@@ -1234,7 +1259,7 @@ class Configuration(ObjectBaseModel):
1234
1259
  """An ORM representation of account info."""
1235
1260
 
1236
1261
  key: str = Field(default=..., description="Account info key")
1237
- value: Dict[str, Any] = Field(default=..., description="Account info")
1262
+ value: dict[str, Any] = Field(default=..., description="Account info")
1238
1263
 
1239
1264
 
1240
1265
  class SavedSearchFilter(PrefectBaseModel):
@@ -1258,7 +1283,7 @@ class SavedSearch(ObjectBaseModel):
1258
1283
  """An ORM representation of saved search data. Represents a set of filter criteria."""
1259
1284
 
1260
1285
  name: str = Field(default=..., description="The name of the saved search.")
1261
- filters: List[SavedSearchFilter] = Field(
1286
+ filters: list[SavedSearchFilter] = Field(
1262
1287
  default_factory=list, description="The filter set for the saved search."
1263
1288
  )
1264
1289
 
@@ -1281,11 +1306,11 @@ class Log(ObjectBaseModel):
1281
1306
  class QueueFilter(PrefectBaseModel):
1282
1307
  """Filter criteria definition for a work queue."""
1283
1308
 
1284
- tags: Optional[List[str]] = Field(
1309
+ tags: Optional[list[str]] = Field(
1285
1310
  default=None,
1286
1311
  description="Only include flow runs with these tags in the work queue.",
1287
1312
  )
1288
- deployment_ids: Optional[List[UUID]] = Field(
1313
+ deployment_ids: Optional[list[UUID]] = Field(
1289
1314
  default=None,
1290
1315
  description="Only include flow runs from these deployments in the work queue.",
1291
1316
  )
@@ -1345,7 +1370,7 @@ class WorkQueueHealthPolicy(PrefectBaseModel):
1345
1370
  )
1346
1371
 
1347
1372
  def evaluate_health_status(
1348
- self, late_runs_count: int, last_polled: Optional[DateTime] = None
1373
+ self, late_runs_count: int, last_polled: Optional[pendulum.DateTime] = None
1349
1374
  ) -> bool:
1350
1375
  """
1351
1376
  Given empirical information about the state of the work queue, evaluate its health status.
@@ -1397,10 +1422,10 @@ class FlowRunNotificationPolicy(ObjectBaseModel):
1397
1422
  is_active: bool = Field(
1398
1423
  default=True, description="Whether the policy is currently active"
1399
1424
  )
1400
- state_names: List[str] = Field(
1425
+ state_names: list[str] = Field(
1401
1426
  default=..., description="The flow run states that trigger notifications"
1402
1427
  )
1403
- tags: List[str] = Field(
1428
+ tags: list[str] = Field(
1404
1429
  default=...,
1405
1430
  description="The flow run tags that trigger notifications (set [] to disable)",
1406
1431
  )
@@ -1422,7 +1447,7 @@ class FlowRunNotificationPolicy(ObjectBaseModel):
1422
1447
 
1423
1448
  @field_validator("message_template")
1424
1449
  @classmethod
1425
- def validate_message_template_variables(cls, v):
1450
+ def validate_message_template_variables(cls, v: Optional[str]) -> Optional[str]:
1426
1451
  return validate_message_template_variables(v)
1427
1452
 
1428
1453
 
@@ -1454,7 +1479,7 @@ class WorkPool(ObjectBaseModel):
1454
1479
  default=None, description="A description of the work pool."
1455
1480
  )
1456
1481
  type: str = Field(description="The work pool type.")
1457
- base_job_template: Dict[str, Any] = Field(
1482
+ base_job_template: dict[str, Any] = Field(
1458
1483
  default_factory=dict, description="The work pool's base job template."
1459
1484
  )
1460
1485
  is_paused: bool = Field(
@@ -1469,10 +1494,12 @@ class WorkPool(ObjectBaseModel):
1469
1494
  )
1470
1495
 
1471
1496
  # this required field has a default of None so that the custom validator
1472
- # below will be called and produce a more helpful error message
1473
- default_queue_id: UUID = Field(
1474
- None, description="The id of the pool's default queue."
1475
- )
1497
+ # below will be called and produce a more helpful error message. Because
1498
+ # the field metadata is attached via an annotation, the default is hidden
1499
+ # from type checkers.
1500
+ default_queue_id: Annotated[
1501
+ UUID, Field(default=None, description="The id of the pool's default queue.")
1502
+ ]
1476
1503
 
1477
1504
  @property
1478
1505
  def is_push_pool(self) -> bool:
@@ -1484,7 +1511,7 @@ class WorkPool(ObjectBaseModel):
1484
1511
 
1485
1512
  @field_validator("default_queue_id")
1486
1513
  @classmethod
1487
- def helpful_error_for_missing_default_queue_id(cls, v):
1514
+ def helpful_error_for_missing_default_queue_id(cls, v: Optional[UUID]) -> UUID:
1488
1515
  return validate_default_queue_id_not_none(v)
1489
1516
 
1490
1517
 
@@ -1495,8 +1522,8 @@ class Worker(ObjectBaseModel):
1495
1522
  work_pool_id: UUID = Field(
1496
1523
  description="The work pool with which the queue is associated."
1497
1524
  )
1498
- last_heartbeat_time: datetime.datetime = Field(
1499
- None, description="The last time the worker process sent a heartbeat."
1525
+ last_heartbeat_time: Optional[datetime.datetime] = Field(
1526
+ default=None, description="The last time the worker process sent a heartbeat."
1500
1527
  )
1501
1528
  heartbeat_interval_seconds: Optional[int] = Field(
1502
1529
  default=None,
@@ -1529,14 +1556,14 @@ class Artifact(ObjectBaseModel):
1529
1556
  default=None, description="A markdown-enabled description of the artifact."
1530
1557
  )
1531
1558
  # data will eventually be typed as `Optional[Union[Result, Any]]`
1532
- data: Optional[Union[Dict[str, Any], Any]] = Field(
1559
+ data: Optional[Union[dict[str, Any], Any]] = Field(
1533
1560
  default=None,
1534
1561
  description=(
1535
1562
  "Data associated with the artifact, e.g. a result.; structure depends on"
1536
1563
  " the artifact type."
1537
1564
  ),
1538
1565
  )
1539
- metadata_: Optional[Dict[str, str]] = Field(
1566
+ metadata_: Optional[dict[str, str]] = Field(
1540
1567
  default=None,
1541
1568
  description=(
1542
1569
  "User-defined artifact metadata. Content must be string key and value"
@@ -1552,7 +1579,9 @@ class Artifact(ObjectBaseModel):
1552
1579
 
1553
1580
  @field_validator("metadata_")
1554
1581
  @classmethod
1555
- def validate_metadata_length(cls, v):
1582
+ def validate_metadata_length(
1583
+ cls, v: Optional[dict[str, str]]
1584
+ ) -> Optional[dict[str, str]]:
1556
1585
  return validate_max_metadata_length(v)
1557
1586
 
1558
1587
 
@@ -1571,14 +1600,14 @@ class ArtifactCollection(ObjectBaseModel):
1571
1600
  description: Optional[str] = Field(
1572
1601
  default=None, description="A markdown-enabled description of the artifact."
1573
1602
  )
1574
- data: Optional[Union[Dict[str, Any], Any]] = Field(
1603
+ data: Optional[Union[dict[str, Any], Any]] = Field(
1575
1604
  default=None,
1576
1605
  description=(
1577
1606
  "Data associated with the artifact, e.g. a result.; structure depends on"
1578
1607
  " the artifact type."
1579
1608
  ),
1580
1609
  )
1581
- metadata_: Optional[Dict[str, str]] = Field(
1610
+ metadata_: Optional[dict[str, str]] = Field(
1582
1611
  default=None,
1583
1612
  description=(
1584
1613
  "User-defined artifact metadata. Content must be string key and value"
@@ -1605,7 +1634,7 @@ class Variable(ObjectBaseModel):
1605
1634
  description="The value of the variable",
1606
1635
  examples=["my_value"],
1607
1636
  )
1608
- tags: List[str] = Field(
1637
+ tags: list[str] = Field(
1609
1638
  default_factory=list,
1610
1639
  description="A list of variable tags",
1611
1640
  examples=[["tag-1", "tag-2"]],
@@ -1630,7 +1659,7 @@ class FlowRunInput(ObjectBaseModel):
1630
1659
 
1631
1660
  @field_validator("key", check_fields=False)
1632
1661
  @classmethod
1633
- def validate_name_characters(cls, v):
1662
+ def validate_name_characters(cls, v: str) -> str:
1634
1663
  raise_on_name_alphanumeric_dashes_only(v)
1635
1664
  return v
1636
1665
 
@@ -1675,7 +1704,7 @@ class CsrfToken(ObjectBaseModel):
1675
1704
  )
1676
1705
 
1677
1706
 
1678
- __getattr__ = getattr_migration(__name__)
1707
+ __getattr__: Callable[[str], Any] = getattr_migration(__name__)
1679
1708
 
1680
1709
 
1681
1710
  class Integration(PrefectBaseModel):
@@ -1693,7 +1722,7 @@ class WorkerMetadata(PrefectBaseModel):
1693
1722
  should support flexible metadata.
1694
1723
  """
1695
1724
 
1696
- integrations: List[Integration] = Field(
1725
+ integrations: list[Integration] = Field(
1697
1726
  default=..., description="Prefect integrations installed in the worker."
1698
1727
  )
1699
- model_config = ConfigDict(extra="allow")
1728
+ model_config: ClassVar[ConfigDict] = ConfigDict(extra="allow")