prefect-client 3.1.5__tar.gz → 3.1.7__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.
Files changed (259) hide show
  1. {prefect-client-3.1.5 → prefect-client-3.1.7}/MANIFEST.in +3 -3
  2. {prefect-client-3.1.5/src/prefect_client.egg-info → prefect-client-3.1.7}/PKG-INFO +4 -2
  3. {prefect-client-3.1.5 → prefect-client-3.1.7}/README.md +3 -1
  4. {prefect-client-3.1.5 → prefect-client-3.1.7}/requirements-client.txt +1 -0
  5. {prefect-client-3.1.5 → prefect-client-3.1.7}/setup.cfg +1 -0
  6. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/__init__.py +3 -0
  7. prefect-client-3.1.7/src/prefect/_experimental/lineage.py +181 -0
  8. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/_internal/compatibility/async_dispatch.py +38 -9
  9. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/_internal/compatibility/migration.py +1 -1
  10. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/_internal/concurrency/api.py +52 -52
  11. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/_internal/concurrency/calls.py +59 -35
  12. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/_internal/concurrency/cancellation.py +34 -18
  13. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/_internal/concurrency/event_loop.py +7 -6
  14. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/_internal/concurrency/threads.py +41 -33
  15. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/_internal/concurrency/waiters.py +28 -21
  16. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/_internal/pydantic/v1_schema.py +2 -2
  17. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/_internal/pydantic/v2_schema.py +10 -9
  18. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/_internal/pydantic/v2_validated_func.py +15 -10
  19. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/_internal/retries.py +15 -6
  20. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/_internal/schemas/bases.py +11 -8
  21. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/_internal/schemas/validators.py +7 -5
  22. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/_version.py +3 -3
  23. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/automations.py +53 -47
  24. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/blocks/abstract.py +12 -10
  25. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/blocks/core.py +148 -19
  26. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/blocks/system.py +2 -1
  27. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/cache_policies.py +11 -11
  28. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/client/__init__.py +3 -1
  29. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/client/base.py +36 -37
  30. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/client/cloud.py +26 -19
  31. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/client/collections.py +2 -2
  32. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/client/orchestration.py +430 -273
  33. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/client/schemas/__init__.py +24 -0
  34. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/client/schemas/actions.py +128 -121
  35. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/client/schemas/filters.py +1 -1
  36. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/client/schemas/objects.py +114 -85
  37. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/client/schemas/responses.py +19 -20
  38. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/client/schemas/schedules.py +136 -93
  39. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/client/subscriptions.py +30 -15
  40. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/client/utilities.py +46 -36
  41. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/concurrency/asyncio.py +6 -9
  42. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/concurrency/sync.py +35 -5
  43. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/context.py +40 -32
  44. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/deployments/flow_runs.py +6 -8
  45. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/deployments/runner.py +14 -14
  46. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/deployments/steps/core.py +3 -1
  47. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/deployments/steps/pull.py +60 -12
  48. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/docker/__init__.py +1 -1
  49. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/events/clients.py +55 -4
  50. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/events/filters.py +1 -1
  51. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/events/related.py +2 -1
  52. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/events/schemas/events.py +26 -21
  53. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/events/utilities.py +3 -2
  54. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/events/worker.py +8 -0
  55. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/filesystems.py +3 -3
  56. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/flow_engine.py +87 -87
  57. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/flow_runs.py +7 -5
  58. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/flows.py +218 -176
  59. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/logging/configuration.py +1 -1
  60. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/logging/highlighters.py +1 -2
  61. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/logging/loggers.py +30 -20
  62. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/main.py +17 -24
  63. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/results.py +43 -22
  64. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/runner/runner.py +43 -21
  65. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/runner/server.py +30 -32
  66. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/runner/storage.py +3 -3
  67. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/runner/submit.py +3 -6
  68. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/runner/utils.py +6 -6
  69. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/runtime/flow_run.py +7 -0
  70. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/serializers.py +28 -24
  71. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/settings/constants.py +2 -2
  72. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/settings/legacy.py +1 -1
  73. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/settings/models/experiments.py +5 -0
  74. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/settings/models/server/events.py +10 -0
  75. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/task_engine.py +87 -26
  76. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/task_runners.py +2 -2
  77. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/task_worker.py +43 -25
  78. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/tasks.py +148 -142
  79. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/telemetry/bootstrap.py +15 -2
  80. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/telemetry/instrumentation.py +1 -1
  81. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/telemetry/processors.py +10 -7
  82. prefect-client-3.1.7/src/prefect/telemetry/run_telemetry.py +231 -0
  83. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/transactions.py +14 -14
  84. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/types/__init__.py +5 -5
  85. prefect-client-3.1.7/src/prefect/utilities/__init__.py +0 -0
  86. prefect-client-3.1.7/src/prefect/utilities/_engine.py +96 -0
  87. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/utilities/annotations.py +25 -18
  88. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/utilities/asyncutils.py +126 -140
  89. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/utilities/callables.py +87 -78
  90. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/utilities/collections.py +278 -117
  91. prefect-client-3.1.7/src/prefect/utilities/compat.py +23 -0
  92. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/utilities/context.py +6 -5
  93. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/utilities/dispatch.py +23 -12
  94. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/utilities/dockerutils.py +33 -32
  95. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/utilities/engine.py +126 -239
  96. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/utilities/filesystem.py +18 -15
  97. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/utilities/hashing.py +10 -11
  98. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/utilities/importtools.py +40 -27
  99. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/utilities/math.py +9 -5
  100. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/utilities/names.py +3 -3
  101. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/utilities/processutils.py +121 -57
  102. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/utilities/pydantic.py +41 -36
  103. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/utilities/render_swagger.py +22 -12
  104. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/utilities/schema_tools/__init__.py +2 -1
  105. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/utilities/schema_tools/hydration.py +50 -43
  106. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/utilities/schema_tools/validation.py +52 -42
  107. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/utilities/services.py +13 -12
  108. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/utilities/templating.py +45 -45
  109. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/utilities/text.py +2 -1
  110. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/utilities/timeout.py +4 -4
  111. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/utilities/urls.py +9 -4
  112. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/utilities/visualization.py +46 -24
  113. prefect-client-3.1.7/src/prefect/variables.py +259 -0
  114. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/workers/base.py +15 -8
  115. {prefect-client-3.1.5 → prefect-client-3.1.7/src/prefect_client.egg-info}/PKG-INFO +4 -2
  116. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect_client.egg-info/SOURCES.txt +4 -0
  117. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect_client.egg-info/requires.txt +1 -0
  118. prefect-client-3.1.5/src/prefect/utilities/compat.py +0 -31
  119. prefect-client-3.1.5/src/prefect/variables.py +0 -150
  120. {prefect-client-3.1.5 → prefect-client-3.1.7}/LICENSE +0 -0
  121. {prefect-client-3.1.5 → prefect-client-3.1.7}/requirements-dev.txt +0 -0
  122. {prefect-client-3.1.5 → prefect-client-3.1.7}/requirements.txt +0 -0
  123. {prefect-client-3.1.5 → prefect-client-3.1.7}/setup.py +0 -0
  124. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/.prefectignore +0 -0
  125. {prefect-client-3.1.5/src/prefect/_internal → prefect-client-3.1.7/src/prefect/_experimental}/__init__.py +0 -0
  126. {prefect-client-3.1.5/src/prefect/_internal/compatibility → prefect-client-3.1.7/src/prefect/_internal}/__init__.py +0 -0
  127. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/_internal/_logging.py +0 -0
  128. {prefect-client-3.1.5/src/prefect/_internal/pydantic/annotations → prefect-client-3.1.7/src/prefect/_internal/compatibility}/__init__.py +0 -0
  129. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/_internal/compatibility/deprecated.py +0 -0
  130. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/_internal/concurrency/__init__.py +0 -0
  131. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/_internal/concurrency/inspection.py +0 -0
  132. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/_internal/concurrency/primitives.py +0 -0
  133. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/_internal/concurrency/services.py +0 -0
  134. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/_internal/integrations.py +0 -0
  135. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/_internal/pydantic/__init__.py +0 -0
  136. {prefect-client-3.1.5/src/prefect/_internal/schemas → prefect-client-3.1.7/src/prefect/_internal/pydantic/annotations}/__init__.py +0 -0
  137. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/_internal/pydantic/annotations/pendulum.py +0 -0
  138. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/_internal/pydantic/schemas.py +0 -0
  139. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/_internal/pytz.py +0 -0
  140. {prefect-client-3.1.5/src/prefect/client/types → prefect-client-3.1.7/src/prefect/_internal/schemas}/__init__.py +0 -0
  141. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/_internal/schemas/fields.py +0 -0
  142. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/_internal/schemas/serializers.py +0 -0
  143. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/agent.py +0 -0
  144. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/artifacts.py +0 -0
  145. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/blocks/__init__.py +0 -0
  146. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/blocks/fields.py +0 -0
  147. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/blocks/notifications.py +0 -0
  148. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/blocks/redis.py +0 -0
  149. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/blocks/webhook.py +0 -0
  150. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/client/constants.py +0 -0
  151. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/client/schemas/sorting.py +0 -0
  152. {prefect-client-3.1.5/src/prefect/concurrency → prefect-client-3.1.7/src/prefect/client/types}/__init__.py +0 -0
  153. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/client/types/flexible_schedule_list.py +0 -0
  154. {prefect-client-3.1.5/src/prefect/concurrency/v1 → prefect-client-3.1.7/src/prefect/concurrency}/__init__.py +0 -0
  155. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/concurrency/context.py +0 -0
  156. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/concurrency/events.py +0 -0
  157. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/concurrency/services.py +0 -0
  158. {prefect-client-3.1.5/src/prefect/events/cli → prefect-client-3.1.7/src/prefect/concurrency/v1}/__init__.py +0 -0
  159. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/concurrency/v1/asyncio.py +0 -0
  160. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/concurrency/v1/context.py +0 -0
  161. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/concurrency/v1/events.py +0 -0
  162. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/concurrency/v1/services.py +0 -0
  163. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/concurrency/v1/sync.py +0 -0
  164. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/deployments/__init__.py +0 -0
  165. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/deployments/base.py +0 -0
  166. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/deployments/deployments.py +0 -0
  167. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/deployments/schedules.py +0 -0
  168. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/deployments/steps/__init__.py +0 -0
  169. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/deployments/steps/utility.py +0 -0
  170. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/docker/docker_image.py +0 -0
  171. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/engine.py +0 -0
  172. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/events/__init__.py +0 -0
  173. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/events/actions.py +0 -0
  174. {prefect-client-3.1.5/src/prefect/events/schemas → prefect-client-3.1.7/src/prefect/events/cli}/__init__.py +0 -0
  175. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/events/cli/automations.py +0 -0
  176. {prefect-client-3.1.5/src/prefect/locking → prefect-client-3.1.7/src/prefect/events/schemas}/__init__.py +0 -0
  177. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/events/schemas/automations.py +0 -0
  178. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/events/schemas/deployment_triggers.py +0 -0
  179. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/events/schemas/labelling.py +0 -0
  180. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/exceptions.py +0 -0
  181. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/futures.py +0 -0
  182. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/infrastructure/__init__.py +0 -0
  183. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/infrastructure/base.py +0 -0
  184. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/infrastructure/provisioners/__init__.py +0 -0
  185. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/infrastructure/provisioners/cloud_run.py +0 -0
  186. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/infrastructure/provisioners/container_instance.py +0 -0
  187. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/infrastructure/provisioners/ecs.py +0 -0
  188. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/infrastructure/provisioners/modal.py +0 -0
  189. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/input/__init__.py +0 -0
  190. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/input/actions.py +0 -0
  191. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/input/run_input.py +0 -0
  192. {prefect-client-3.1.5/src/prefect/settings/models → prefect-client-3.1.7/src/prefect/locking}/__init__.py +0 -0
  193. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/locking/filesystem.py +0 -0
  194. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/locking/memory.py +0 -0
  195. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/locking/protocol.py +0 -0
  196. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/logging/__init__.py +0 -0
  197. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/logging/filters.py +0 -0
  198. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/logging/formatters.py +0 -0
  199. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/logging/handlers.py +0 -0
  200. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/logging/logging.yml +0 -0
  201. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/plugins.py +0 -0
  202. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/py.typed +0 -0
  203. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/records/__init__.py +0 -0
  204. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/records/base.py +0 -0
  205. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/records/filesystem.py +0 -0
  206. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/records/memory.py +0 -0
  207. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/records/result_store.py +0 -0
  208. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/runner/__init__.py +0 -0
  209. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/runtime/__init__.py +0 -0
  210. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/runtime/deployment.py +0 -0
  211. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/runtime/task_run.py +0 -0
  212. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/server/api/collections_data/views/aggregate-worker-metadata.json +0 -0
  213. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/server/api/static/prefect-logo-mark-gradient.png +0 -0
  214. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/settings/__init__.py +0 -0
  215. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/settings/base.py +0 -0
  216. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/settings/context.py +0 -0
  217. {prefect-client-3.1.5/src/prefect/utilities → prefect-client-3.1.7/src/prefect/settings/models}/__init__.py +0 -0
  218. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/settings/models/api.py +0 -0
  219. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/settings/models/cli.py +0 -0
  220. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/settings/models/client.py +0 -0
  221. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/settings/models/cloud.py +0 -0
  222. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/settings/models/deployments.py +0 -0
  223. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/settings/models/flows.py +0 -0
  224. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/settings/models/internal.py +0 -0
  225. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/settings/models/logging.py +0 -0
  226. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/settings/models/results.py +0 -0
  227. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/settings/models/root.py +0 -0
  228. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/settings/models/runner.py +0 -0
  229. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/settings/models/server/__init__.py +0 -0
  230. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/settings/models/server/api.py +0 -0
  231. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/settings/models/server/database.py +0 -0
  232. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/settings/models/server/deployments.py +0 -0
  233. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/settings/models/server/ephemeral.py +0 -0
  234. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/settings/models/server/flow_run_graph.py +0 -0
  235. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/settings/models/server/root.py +0 -0
  236. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/settings/models/server/services.py +0 -0
  237. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/settings/models/server/tasks.py +0 -0
  238. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/settings/models/server/ui.py +0 -0
  239. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/settings/models/tasks.py +0 -0
  240. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/settings/models/testing.py +0 -0
  241. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/settings/models/worker.py +0 -0
  242. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/settings/profiles.py +0 -0
  243. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/settings/profiles.toml +0 -0
  244. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/settings/sources.py +0 -0
  245. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/states.py +0 -0
  246. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/task_runs.py +0 -0
  247. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/telemetry/__init__.py +0 -0
  248. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/telemetry/logging.py +0 -0
  249. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/types/entrypoint.py +0 -0
  250. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/utilities/slugify.py +0 -0
  251. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/workers/__init__.py +0 -0
  252. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/workers/block.py +0 -0
  253. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/workers/cloud.py +0 -0
  254. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/workers/process.py +0 -0
  255. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/workers/server.py +0 -0
  256. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect/workers/utilities.py +0 -0
  257. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect_client.egg-info/dependency_links.txt +0 -0
  258. {prefect-client-3.1.5 → prefect-client-3.1.7}/src/prefect_client.egg-info/top_level.txt +0 -0
  259. {prefect-client-3.1.5 → prefect-client-3.1.7}/versioneer.py +0 -0
@@ -25,9 +25,9 @@ include src/prefect/server/api/collections_data/views/*.json
25
25
 
26
26
  # Migrations
27
27
  include src/prefect/server/database/alembic.ini
28
- include src/prefect/server/database/migrations/*
29
- include src/prefect/server/database/migrations/versions/*
30
- include src/prefect/server/database/migrations/versions/*/*
28
+ include src/prefect/server/database/_migrations/*
29
+ include src/prefect/server/database/_migrations/versions/*
30
+ include src/prefect/server/database/_migrations/versions/*/*
31
31
 
32
32
  # SQL templates
33
33
  graft src/prefect/server/database/sql
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: prefect-client
3
- Version: 3.1.5
3
+ Version: 3.1.7
4
4
  Summary: Workflow orchestration and management.
5
5
  Home-page: https://www.prefect.io
6
6
  Author: Prefect Technologies, Inc.
@@ -126,7 +126,9 @@ Start with our [friendly tutorial](https://docs.prefect.io/tutorials) or explore
126
126
 
127
127
  ## Join the community
128
128
 
129
- Prefect is made possible by the fastest growing community of thousands of friendly data engineers. Join us in building a new kind of workflow system. The [Prefect Slack community](https://prefect.io/slack) is a fantastic place to learn more about Prefect, ask questions, or get help with workflow design. All community forums, including code contributions, issue discussions, and slack messages are subject to our [Code of Conduct](https://discourse.prefect.io/faq).
129
+ Prefect is made possible by the fastest growing community of thousands of friendly data engineers. Join us in building a new kind of workflow system.
130
+ The [Prefect Slack community](https://prefect.io/slack) is a fantastic place to learn more about Prefect, ask questions, or get help with workflow design.
131
+ All community forums, including code contributions, issue discussions, and Slack messages are subject to our [Code of Conduct](https://github.com/PrefectHQ/prefect/blob/main/CODE_OF_CONDUCT.md).
130
132
 
131
133
  ## Contribute
132
134
 
@@ -98,7 +98,9 @@ Start with our [friendly tutorial](https://docs.prefect.io/tutorials) or explore
98
98
 
99
99
  ## Join the community
100
100
 
101
- Prefect is made possible by the fastest growing community of thousands of friendly data engineers. Join us in building a new kind of workflow system. The [Prefect Slack community](https://prefect.io/slack) is a fantastic place to learn more about Prefect, ask questions, or get help with workflow design. All community forums, including code contributions, issue discussions, and slack messages are subject to our [Code of Conduct](https://discourse.prefect.io/faq).
101
+ Prefect is made possible by the fastest growing community of thousands of friendly data engineers. Join us in building a new kind of workflow system.
102
+ The [Prefect Slack community](https://prefect.io/slack) is a fantastic place to learn more about Prefect, ask questions, or get help with workflow design.
103
+ All community forums, including code contributions, issue discussions, and Slack messages are subject to our [Code of Conduct](https://github.com/PrefectHQ/prefect/blob/main/CODE_OF_CONDUCT.md).
102
104
 
103
105
  ## Contribute
104
106
 
@@ -26,6 +26,7 @@ pydantic_extra_types >= 2.8.2, < 3.0.0
26
26
  pydantic_settings > 2.2.1
27
27
  python_dateutil >= 2.8.2, < 3.0.0
28
28
  python-slugify >= 5.0, < 9.0
29
+ python-socks[asyncio] >= 2.5.3, < 3.0
29
30
  pyyaml >= 5.4.1, < 7.0.0
30
31
  rfc3339-validator >= 0.1.4, < 0.2.0
31
32
  rich >= 11.0, < 14.0
@@ -70,6 +70,7 @@ branch = True
70
70
  [coverage:report]
71
71
  exclude_lines =
72
72
  @(abc\.)?abstractmethod
73
+ if TYPE_CHECKING:
73
74
  omit =
74
75
  src/prefect/server/database/migrations/versions/*
75
76
  ignore_errors = True
@@ -38,6 +38,7 @@ if TYPE_CHECKING:
38
38
  Transaction,
39
39
  unmapped,
40
40
  serve,
41
+ aserve,
41
42
  deploy,
42
43
  pause_flow_run,
43
44
  resume_flow_run,
@@ -66,6 +67,7 @@ _public_api: dict[str, tuple[str, str]] = {
66
67
  "Transaction": (__spec__.parent, ".main"),
67
68
  "unmapped": (__spec__.parent, ".main"),
68
69
  "serve": (__spec__.parent, ".main"),
70
+ "aserve": (__spec__.parent, ".main"),
69
71
  "deploy": (__spec__.parent, ".main"),
70
72
  "pause_flow_run": (__spec__.parent, ".main"),
71
73
  "resume_flow_run": (__spec__.parent, ".main"),
@@ -86,6 +88,7 @@ __all__ = [
86
88
  "Transaction",
87
89
  "unmapped",
88
90
  "serve",
91
+ "aserve",
89
92
  "deploy",
90
93
  "pause_flow_run",
91
94
  "resume_flow_run",
@@ -0,0 +1,181 @@
1
+ from typing import TYPE_CHECKING, Any, Dict, Literal, Optional, Sequence, Union
2
+
3
+ from prefect.events.related import related_resources_from_run_context
4
+ from prefect.events.schemas.events import RelatedResource, Resource
5
+ from prefect.events.utilities import emit_event
6
+ from prefect.settings import get_current_settings
7
+
8
+ if TYPE_CHECKING:
9
+ from prefect.results import ResultStore
10
+
11
+ UpstreamResources = Sequence[Union[RelatedResource, dict[str, str]]]
12
+ DownstreamResources = Sequence[Union[Resource, dict[str, str]]]
13
+
14
+ # Map block types to their URI schemes
15
+ STORAGE_URI_SCHEMES = {
16
+ "local-file-system": "file://{path}",
17
+ "s3-bucket": "s3://{storage.bucket_name}/{path}",
18
+ "gcs-bucket": "gs://{storage.bucket}/{path}",
19
+ "azure-blob-storage": "azure-blob://{storage.container_name}/{path}",
20
+ }
21
+
22
+
23
+ def get_result_resource_uri(
24
+ store: "ResultStore",
25
+ key: str,
26
+ ) -> Optional[str]:
27
+ """
28
+ Generate a URI for a result based on its storage backend.
29
+
30
+ Args:
31
+ store: A `ResultStore` instance.
32
+ key: The key of the result to generate a URI for.
33
+ """
34
+ storage = store.result_storage
35
+ if storage is None:
36
+ return
37
+
38
+ path = store._resolved_key_path(key)
39
+
40
+ block_type = storage.get_block_type_slug()
41
+ if block_type and block_type in STORAGE_URI_SCHEMES:
42
+ return STORAGE_URI_SCHEMES[block_type].format(storage=storage, path=path)
43
+
44
+ # Generic fallback
45
+ return f"prefect://{block_type}/{path}"
46
+
47
+
48
+ async def emit_lineage_event(
49
+ event_name: str,
50
+ upstream_resources: Optional[UpstreamResources] = None,
51
+ downstream_resources: Optional[DownstreamResources] = None,
52
+ direction_of_run_from_event: Literal["upstream", "downstream"] = "downstream",
53
+ ) -> None:
54
+ """Emit lineage events showing relationships between resources.
55
+
56
+ Args:
57
+ event_name: The name of the event to emit
58
+ upstream_resources: Optional list of RelatedResources that were upstream of
59
+ the event
60
+ downstream_resources: Optional list of Resources that were downstream
61
+ of the event
62
+ direction_of_run_from_event: The direction of the current run from
63
+ the event. E.g., if we're in a flow run and
64
+ `direction_of_run_from_event` is "downstream", then the flow run is
65
+ considered downstream of the resource's event.
66
+ """
67
+ from prefect.client.orchestration import get_client # Avoid a circular import
68
+
69
+ if not get_current_settings().experiments.lineage_events_enabled:
70
+ return
71
+
72
+ upstream_resources = list(upstream_resources) if upstream_resources else []
73
+ downstream_resources = list(downstream_resources) if downstream_resources else []
74
+
75
+ async with get_client() as client:
76
+ related_resources = await related_resources_from_run_context(client)
77
+
78
+ # NOTE: We handle adding run-related resources to the event here instead of in
79
+ # the EventsWorker because not all run-related resources are upstream from
80
+ # every lineage event (they might be downstream). The EventsWorker only adds
81
+ # related resources to the "related" field in the event, which, for
82
+ # lineage-related events, tracks upstream resources only. For downstream
83
+ # resources, we need to emit an event for each downstream resource.
84
+ if direction_of_run_from_event == "downstream":
85
+ downstream_resources.extend(related_resources)
86
+ else:
87
+ upstream_resources.extend(related_resources)
88
+
89
+ # Emit an event for each downstream resource. This is necessary because
90
+ # our event schema allows one primary resource and many related resources,
91
+ # and for the purposes of lineage, related resources can only represent
92
+ # upstream resources.
93
+ for resource in downstream_resources:
94
+ # Downstream lineage resources need to have the
95
+ # prefect.resource.lineage-group label. All upstram resources from a
96
+ # downstream resource with this label will be considered lineage-related
97
+ # resources.
98
+ if "prefect.resource.lineage-group" not in resource:
99
+ resource["prefect.resource.lineage-group"] = "global"
100
+
101
+ emit_kwargs: Dict[str, Any] = {
102
+ "event": event_name,
103
+ "resource": resource,
104
+ "related": upstream_resources,
105
+ }
106
+
107
+ emit_event(**emit_kwargs)
108
+
109
+
110
+ async def emit_result_read_event(
111
+ store: "ResultStore",
112
+ result_key: str,
113
+ downstream_resources: Optional[DownstreamResources] = None,
114
+ cached: bool = False,
115
+ ) -> None:
116
+ """
117
+ Emit a lineage event showing a task or flow result was read.
118
+
119
+ Args:
120
+ store: A `ResultStore` instance.
121
+ result_key: The key of the result to generate a URI for.
122
+ downstream_resources: List of resources that were
123
+ downstream of the event's resource.
124
+ """
125
+ if not get_current_settings().experiments.lineage_events_enabled:
126
+ return
127
+
128
+ result_resource_uri = get_result_resource_uri(store, result_key)
129
+ if result_resource_uri:
130
+ upstream_resources = [
131
+ RelatedResource(
132
+ root={
133
+ "prefect.resource.id": result_resource_uri,
134
+ "prefect.resource.role": "result",
135
+ }
136
+ )
137
+ ]
138
+ event_name = "prefect.result.read"
139
+ if cached:
140
+ event_name += ".cached"
141
+
142
+ await emit_lineage_event(
143
+ event_name=event_name,
144
+ upstream_resources=upstream_resources,
145
+ downstream_resources=downstream_resources,
146
+ direction_of_run_from_event="downstream",
147
+ )
148
+
149
+
150
+ async def emit_result_write_event(
151
+ store: "ResultStore",
152
+ result_key: str,
153
+ upstream_resources: Optional[UpstreamResources] = None,
154
+ ) -> None:
155
+ """
156
+ Emit a lineage event showing a task or flow result was written.
157
+
158
+ Args:
159
+ store: A `ResultStore` instance.
160
+ result_key: The key of the result to generate a URI for.
161
+ upstream_resources: Optional list of resources that were
162
+ upstream of the event's resource.
163
+ """
164
+ if not get_current_settings().experiments.lineage_events_enabled:
165
+ return
166
+
167
+ result_resource_uri = get_result_resource_uri(store, result_key)
168
+ if result_resource_uri:
169
+ downstream_resources = [
170
+ {
171
+ "prefect.resource.id": result_resource_uri,
172
+ "prefect.resource.role": "result",
173
+ "prefect.resource.lineage-group": "global",
174
+ }
175
+ ]
176
+ await emit_lineage_event(
177
+ event_name="prefect.result.write",
178
+ upstream_resources=upstream_resources,
179
+ downstream_resources=downstream_resources,
180
+ direction_of_run_from_event="upstream",
181
+ )
@@ -1,11 +1,12 @@
1
1
  import asyncio
2
2
  import inspect
3
3
  from functools import wraps
4
- from typing import Any, Callable, Coroutine, Optional, TypeVar, Union
4
+ from typing import TYPE_CHECKING, Any, Callable, Coroutine, Optional, TypeVar, Union
5
5
 
6
6
  from typing_extensions import ParamSpec
7
7
 
8
- from prefect.tasks import Task
8
+ if TYPE_CHECKING:
9
+ from prefect.tasks import Task
9
10
 
10
11
  R = TypeVar("R")
11
12
  P = ParamSpec("P")
@@ -13,20 +14,46 @@ P = ParamSpec("P")
13
14
 
14
15
  def is_in_async_context() -> bool:
15
16
  """
16
- Returns True if called from within an async context (coroutine or running event loop)
17
+ Returns True if called from within an async context.
18
+
19
+ An async context is one of:
20
+ - a coroutine
21
+ - a running event loop
22
+ - a task or flow that is async
17
23
  """
24
+ from prefect.context import get_run_context
25
+ from prefect.exceptions import MissingContextError
26
+
18
27
  try:
19
- asyncio.get_running_loop()
20
- return True
21
- except RuntimeError:
22
- return False
28
+ run_ctx = get_run_context()
29
+ parent_obj = getattr(run_ctx, "task", None)
30
+ if not parent_obj:
31
+ parent_obj = getattr(run_ctx, "flow", None)
32
+ return getattr(parent_obj, "isasync", True)
33
+ except MissingContextError:
34
+ # not in an execution context, make best effort to
35
+ # decide whether to syncify
36
+ try:
37
+ asyncio.get_running_loop()
38
+ return True
39
+ except RuntimeError:
40
+ return False
23
41
 
24
42
 
25
- def _is_acceptable_callable(obj: Union[Callable, Task]) -> bool:
43
+ def _is_acceptable_callable(
44
+ obj: Union[Callable[P, R], "Task[P, R]", classmethod],
45
+ ) -> bool:
26
46
  if inspect.iscoroutinefunction(obj):
27
47
  return True
28
- if isinstance(obj, Task) and inspect.iscoroutinefunction(obj.fn):
48
+
49
+ # Check if a task or flow. Need to avoid importing `Task` or `Flow` here
50
+ # due to circular imports.
51
+ if (fn := getattr(obj, "fn", None)) and inspect.iscoroutinefunction(fn):
29
52
  return True
53
+
54
+ if isinstance(obj, classmethod) and inspect.iscoroutinefunction(obj.__func__):
55
+ return True
56
+
30
57
  return False
31
58
 
32
59
 
@@ -56,6 +83,8 @@ def async_dispatch(
56
83
 
57
84
  if should_run_sync:
58
85
  return sync_fn(*args, **kwargs)
86
+ if isinstance(async_impl, classmethod):
87
+ return async_impl.__func__(*args, **kwargs)
59
88
  return async_impl(*args, **kwargs)
60
89
 
61
90
  return wrapper # type: ignore
@@ -86,7 +86,7 @@ REMOVED_IN_V3 = {
86
86
  # See src/prefect/filesystems.py for an example
87
87
 
88
88
 
89
- def import_string_class_method(new_location: str) -> Callable:
89
+ def import_string_class_method(new_location: str) -> Callable[..., Any]:
90
90
  """
91
91
  Handle moved class methods.
92
92
 
@@ -6,51 +6,48 @@ import abc
6
6
  import asyncio
7
7
  import concurrent.futures
8
8
  import contextlib
9
- from typing import (
10
- Awaitable,
11
- Callable,
12
- ContextManager,
13
- Iterable,
14
- Optional,
15
- TypeVar,
16
- Union,
17
- )
9
+ from collections.abc import Awaitable, Iterable
10
+ from contextlib import AbstractContextManager
11
+ from typing import Any, Callable, Optional, Union, cast
18
12
 
19
- from typing_extensions import ParamSpec
13
+ from typing_extensions import ParamSpec, TypeAlias, TypeVar
20
14
 
21
15
  from prefect._internal.concurrency.threads import (
22
16
  WorkerThread,
23
17
  get_global_loop,
24
18
  in_global_loop,
25
19
  )
26
- from prefect._internal.concurrency.waiters import (
27
- AsyncWaiter,
28
- Call,
29
- SyncWaiter,
30
- )
20
+ from prefect._internal.concurrency.waiters import AsyncWaiter, Call, SyncWaiter
31
21
 
32
22
  P = ParamSpec("P")
33
- T = TypeVar("T")
34
- Future = Union[concurrent.futures.Future, asyncio.Future]
23
+ T = TypeVar("T", infer_variance=True)
24
+ Future = Union[concurrent.futures.Future[T], asyncio.Future[T]]
25
+
26
+ _SyncOrAsyncCallable: TypeAlias = Callable[P, Union[T, Awaitable[T]]]
35
27
 
36
28
 
37
- def create_call(__fn: Callable[P, T], *args: P.args, **kwargs: P.kwargs) -> Call[T]:
38
- return Call.new(__fn, *args, **kwargs)
29
+ def create_call(
30
+ __fn: _SyncOrAsyncCallable[P, T], *args: P.args, **kwargs: P.kwargs
31
+ ) -> Call[T]:
32
+ return Call[T].new(__fn, *args, **kwargs)
39
33
 
40
34
 
41
- def _cast_to_call(call_like: Union[Callable[[], T], Call[T]]) -> Call[T]:
35
+ def cast_to_call(
36
+ call_like: Union["_SyncOrAsyncCallable[[], T]", Call[T]],
37
+ ) -> Call[T]:
42
38
  if isinstance(call_like, Call):
43
- return call_like
39
+ return cast(Call[T], call_like)
44
40
  else:
45
41
  return create_call(call_like)
46
42
 
47
43
 
48
44
  class _base(abc.ABC):
49
- @abc.abstractstaticmethod
45
+ @staticmethod
46
+ @abc.abstractmethod
50
47
  def wait_for_call_in_loop_thread(
51
- __call: Union[Callable[[], T], Call[T]],
48
+ __call: Union["_SyncOrAsyncCallable[[], Any]", Call[T]],
52
49
  timeout: Optional[float] = None,
53
- done_callbacks: Optional[Iterable[Call]] = None,
50
+ done_callbacks: Optional[Iterable[Call[Any]]] = None,
54
51
  ) -> T:
55
52
  """
56
53
  Schedule a function in the global worker thread and wait for completion.
@@ -59,11 +56,12 @@ class _base(abc.ABC):
59
56
  """
60
57
  raise NotImplementedError()
61
58
 
62
- @abc.abstractstaticmethod
59
+ @staticmethod
60
+ @abc.abstractmethod
63
61
  def wait_for_call_in_new_thread(
64
- __call: Union[Callable[[], T], Call[T]],
62
+ __call: Union["_SyncOrAsyncCallable[[], T]", Call[T]],
65
63
  timeout: Optional[float] = None,
66
- done_callbacks: Optional[Iterable[Call]] = None,
64
+ done_callbacks: Optional[Iterable[Call[Any]]] = None,
67
65
  ) -> T:
68
66
  """
69
67
  Schedule a function in a new worker thread.
@@ -74,14 +72,15 @@ class _base(abc.ABC):
74
72
 
75
73
  @staticmethod
76
74
  def call_soon_in_new_thread(
77
- __call: Union[Callable[[], T], Call[T]], timeout: Optional[float] = None
75
+ __call: Union["_SyncOrAsyncCallable[[], T]", Call[T]],
76
+ timeout: Optional[float] = None,
78
77
  ) -> Call[T]:
79
78
  """
80
79
  Schedule a call for execution in a new worker thread.
81
80
 
82
81
  Returns the submitted call.
83
82
  """
84
- call = _cast_to_call(__call)
83
+ call = cast_to_call(__call)
85
84
  runner = WorkerThread(run_once=True)
86
85
  call.set_timeout(timeout)
87
86
  runner.submit(call)
@@ -89,7 +88,7 @@ class _base(abc.ABC):
89
88
 
90
89
  @staticmethod
91
90
  def call_soon_in_loop_thread(
92
- __call: Union[Callable[[], Awaitable[T]], Call[Awaitable[T]]],
91
+ __call: Union["_SyncOrAsyncCallable[[], T]", Call[T]],
93
92
  timeout: Optional[float] = None,
94
93
  ) -> Call[T]:
95
94
  """
@@ -97,7 +96,7 @@ class _base(abc.ABC):
97
96
 
98
97
  Returns the submitted call.
99
98
  """
100
- call = _cast_to_call(__call)
99
+ call = cast_to_call(__call)
101
100
  runner = get_global_loop()
102
101
  call.set_timeout(timeout)
103
102
  runner.submit(call)
@@ -116,7 +115,7 @@ class _base(abc.ABC):
116
115
 
117
116
  @staticmethod
118
117
  def call_in_loop_thread(
119
- __call: Union[Callable[[], Awaitable[T]], Call[Awaitable[T]]],
118
+ __call: Union[Callable[[], Awaitable[T]], Call[T]],
120
119
  timeout: Optional[float] = None,
121
120
  ) -> T:
122
121
  """
@@ -130,12 +129,12 @@ class _base(abc.ABC):
130
129
  class from_async(_base):
131
130
  @staticmethod
132
131
  async def wait_for_call_in_loop_thread(
133
- __call: Union[Callable[[], Awaitable[T]], Call[Awaitable[T]]],
132
+ __call: Union[Callable[[], Awaitable[T]], Call[T]],
134
133
  timeout: Optional[float] = None,
135
- done_callbacks: Optional[Iterable[Call]] = None,
136
- contexts: Optional[Iterable[ContextManager]] = None,
137
- ) -> Awaitable[T]:
138
- call = _cast_to_call(__call)
134
+ done_callbacks: Optional[Iterable[Call[Any]]] = None,
135
+ contexts: Optional[Iterable[AbstractContextManager[Any]]] = None,
136
+ ) -> T:
137
+ call = cast_to_call(__call)
139
138
  waiter = AsyncWaiter(call)
140
139
  for callback in done_callbacks or []:
141
140
  waiter.add_done_callback(callback)
@@ -150,9 +149,9 @@ class from_async(_base):
150
149
  async def wait_for_call_in_new_thread(
151
150
  __call: Union[Callable[[], T], Call[T]],
152
151
  timeout: Optional[float] = None,
153
- done_callbacks: Optional[Iterable[Call]] = None,
152
+ done_callbacks: Optional[Iterable[Call[Any]]] = None,
154
153
  ) -> T:
155
- call = _cast_to_call(__call)
154
+ call = cast_to_call(__call)
156
155
  waiter = AsyncWaiter(call=call)
157
156
  for callback in done_callbacks or []:
158
157
  waiter.add_done_callback(callback)
@@ -169,7 +168,7 @@ class from_async(_base):
169
168
 
170
169
  @staticmethod
171
170
  def call_in_loop_thread(
172
- __call: Union[Callable[[], Awaitable[T]], Call[Awaitable[T]]],
171
+ __call: Union[Callable[[], Awaitable[T]], Call[T]],
173
172
  timeout: Optional[float] = None,
174
173
  ) -> Awaitable[T]:
175
174
  call = _base.call_soon_in_loop_thread(__call, timeout=timeout)
@@ -181,13 +180,13 @@ class from_sync(_base):
181
180
  def wait_for_call_in_loop_thread(
182
181
  __call: Union[
183
182
  Callable[[], Awaitable[T]],
184
- Union[Callable[[], Awaitable[T]], Call[Awaitable[T]]],
183
+ Call[T],
185
184
  ],
186
185
  timeout: Optional[float] = None,
187
- done_callbacks: Optional[Iterable[Call]] = None,
188
- contexts: Optional[Iterable[ContextManager]] = None,
189
- ) -> Awaitable[T]:
190
- call = _cast_to_call(__call)
186
+ done_callbacks: Optional[Iterable[Call[T]]] = None,
187
+ contexts: Optional[Iterable[AbstractContextManager[Any]]] = None,
188
+ ) -> T:
189
+ call = cast_to_call(__call)
191
190
  waiter = SyncWaiter(call)
192
191
  _base.call_soon_in_loop_thread(call, timeout=timeout)
193
192
  for callback in done_callbacks or []:
@@ -202,9 +201,9 @@ class from_sync(_base):
202
201
  def wait_for_call_in_new_thread(
203
202
  __call: Union[Callable[[], T], Call[T]],
204
203
  timeout: Optional[float] = None,
205
- done_callbacks: Optional[Iterable[Call]] = None,
206
- ) -> Call[T]:
207
- call = _cast_to_call(__call)
204
+ done_callbacks: Optional[Iterable[Call[T]]] = None,
205
+ ) -> T:
206
+ call = cast_to_call(__call)
208
207
  waiter = SyncWaiter(call=call)
209
208
  for callback in done_callbacks or []:
210
209
  waiter.add_done_callback(callback)
@@ -214,20 +213,21 @@ class from_sync(_base):
214
213
 
215
214
  @staticmethod
216
215
  def call_in_new_thread(
217
- __call: Union[Callable[[], T], Call[T]], timeout: Optional[float] = None
216
+ __call: Union["_SyncOrAsyncCallable[[], T]", Call[T]],
217
+ timeout: Optional[float] = None,
218
218
  ) -> T:
219
219
  call = _base.call_soon_in_new_thread(__call, timeout=timeout)
220
220
  return call.result()
221
221
 
222
222
  @staticmethod
223
223
  def call_in_loop_thread(
224
- __call: Union[Callable[[], Awaitable[T]], Call[Awaitable[T]]],
224
+ __call: Union["_SyncOrAsyncCallable[[], T]", Call[T]],
225
225
  timeout: Optional[float] = None,
226
- ) -> T:
226
+ ) -> Union[Awaitable[T], T]:
227
227
  if in_global_loop():
228
228
  # Avoid deadlock where the call is submitted to the loop then the loop is
229
229
  # blocked waiting for the call
230
- call = _cast_to_call(__call)
230
+ call = cast_to_call(__call)
231
231
  return call()
232
232
 
233
233
  call = _base.call_soon_in_loop_thread(__call, timeout=timeout)