Skip to content

Commit 42e5a97

Browse files
authored
Enable black preview style for string formatting support (PrefectHQ#8578)
1 parent b6e686e commit 42e5a97

File tree

133 files changed

+2015
-896
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

133 files changed

+2015
-896
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ repos:
1818
hooks:
1919
- id: black
2020
language_version: python3
21+
args: ['--preview']

scripts/generate-release-notes.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ def get_github_token() -> str:
111111

112112
if not shutil.which("gh"):
113113
print(
114-
"You must provide a GitHub access token via GITHUB_TOKEN or have the gh CLI installed."
114+
"You must provide a GitHub access token via GITHUB_TOKEN or have the gh CLI"
115+
" installed."
115116
)
116117
exit(1)
117118

@@ -129,7 +130,10 @@ def get_github_token() -> str:
129130
match = TOKEN_REGEX.search(output)
130131
if not match:
131132
print(
132-
f"Failed to find token in GitHub CLI output with regex {TOKEN_REGEX.pattern!r}:",
133+
(
134+
"Failed to find token in GitHub CLI output with regex"
135+
f" {TOKEN_REGEX.pattern!r}:"
136+
),
133137
file=sys.stderr,
134138
)
135139
print(output, file=sys.stderr)

scripts/wait-for-server.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ async def main(timeout):
3737
break
3838
if healthcheck_exc is not None:
3939
raise RuntimeError(
40-
"Timed out while attempting to connect to compatibility test server."
40+
"Timed out while attempting to connect to compatibility test"
41+
" server."
4142
)
4243

4344

src/prefect/__init__.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,11 @@ class Prefect1ImportInterceptor(importlib.abc.Loader):
113113
def find_spec(self, fullname, path, target=None):
114114
if fullname in PREFECT_1_ATTRIBUTES:
115115
warnings.warn(
116-
f"Attempted import of {fullname!r}, which is part of Prefect 1.x, "
117-
f"while Prefect {__version__} is installed. If you're "
118-
"upgrading you'll need to update your code, see the Prefect "
119-
"2.x migration guide: `https://orion-docs.prefect.io/migration_guide/`. "
120-
"Otherwise ensure that your code is pinned to the expected version."
116+
f"Attempted import of {fullname!r}, which is part of Prefect 1.x, while"
117+
f" Prefect {__version__} is installed. If you're upgrading you'll need"
118+
" to update your code, see the Prefect 2.x migration guide:"
119+
" `https://orion-docs.prefect.io/migration_guide/`. Otherwise ensure"
120+
" that your code is pinned to the expected version."
121121
)
122122

123123

src/prefect/_internal/compatibility/deprecated.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@
2828
M = TypeVar("M", bound=pydantic.BaseModel)
2929

3030

31-
DEPRECATED_WARNING = "{name} has been deprecated{when}. It will not be available after {end_date}. {help}"
31+
DEPRECATED_WARNING = (
32+
"{name} has been deprecated{when}. It will not be available after {end_date}."
33+
" {help}"
34+
)
3235
DEPRECATED_MOVED_WARNING = (
3336
"{name} has moved to {new_location}. It will not be available at the old import "
3437
"path after {end_date}. {help}"

src/prefect/_internal/compatibility/experimental.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@
2424

2525

2626
EXPERIMENTAL_WARNING = (
27-
"{feature} is experimental. {help}"
28-
"The interface or behavior may change without warning, we recommend pinning versions to prevent unexpected changes. "
29-
"To disable warnings for this group of experiments, disable PREFECT_EXPERIMENTAL_WARN_{group}."
27+
"{feature} is experimental. {help}The interface or behavior may change without"
28+
" warning, we recommend pinning versions to prevent unexpected changes. To disable"
29+
" warnings for this group of experiments, disable"
30+
" PREFECT_EXPERIMENTAL_WARN_{group}."
3031
)
3132

3233
EXPERIMENTAL_ERROR = (

src/prefect/_internal/concurrency/supervisors.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,10 @@ def result(self) -> Union[Awaitable[T], T]:
181181
raise NotImplementedError()
182182

183183
def __repr__(self) -> str:
184-
return f"<{self.__class__.__name__}(id={id(self)}, owner={self.owner_thread_ident})>"
184+
return (
185+
f"<{self.__class__.__name__}(id={id(self)},"
186+
f" owner={self.owner_thread_ident})>"
187+
)
185188

186189

187190
class SyncSupervisor(Supervisor[T]):

src/prefect/agent.py

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ def __init__(
5454
) -> None:
5555
if default_infrastructure and default_infrastructure_document_id:
5656
raise ValueError(
57-
"Provide only one of 'default_infrastructure' and 'default_infrastructure_document_id'."
57+
"Provide only one of 'default_infrastructure' and"
58+
" 'default_infrastructure_document_id'."
5859
)
5960

6061
self.work_queues: Set[str] = set(work_queues) if work_queues else set()
@@ -154,7 +155,8 @@ async def get_work_queues(self) -> AsyncIterator[WorkQueue]:
154155
)
155156
if self.work_pool_name:
156157
self.logger.info(
157-
f"Created work queue {name!r} in work pool {self.work_pool_name!r}."
158+
f"Created work queue {name!r} in work pool"
159+
f" {self.work_pool_name!r}."
158160
)
159161
else:
160162
self.logger.info(f"Created work queue '{name}'.")
@@ -214,7 +216,8 @@ async def get_and_submit_flow_runs(self) -> List[FlowRun]:
214216
submittable_runs.extend(queue_runs)
215217
except ObjectNotFound:
216218
self.logger.error(
217-
f"Work queue {work_queue.name!r} ({work_queue.id}) not found."
219+
f"Work queue {work_queue.name!r} ({work_queue.id}) not"
220+
" found."
218221
)
219222
except Exception as exc:
220223
self.logger.exception(exc)
@@ -231,7 +234,8 @@ async def get_and_submit_flow_runs(self) -> List[FlowRun]:
231234
self.limiter.acquire_on_behalf_of_nowait(flow_run.id)
232235
except anyio.WouldBlock:
233236
self.logger.info(
234-
f"Flow run limit reached; {self.limiter.borrowed_tokens} flow runs in progress."
237+
f"Flow run limit reached; {self.limiter.borrowed_tokens} flow runs"
238+
" in progress."
235239
)
236240
break
237241
else:
@@ -300,12 +304,16 @@ async def cancel_run(self, flow_run: FlowRun) -> None:
300304
"""
301305
if not flow_run.infrastructure_pid:
302306
self.logger.error(
303-
f"Flow run '{flow_run.id}' does not have an infrastructure pid attached. Cancellation cannot be guaranteed."
307+
f"Flow run '{flow_run.id}' does not have an infrastructure pid"
308+
" attached. Cancellation cannot be guaranteed."
304309
)
305310
await self._mark_flow_run_as_cancelled(
306311
flow_run,
307312
state_updates={
308-
"message": "This flow run is missing infrastructure tracking information and cancellation cannot be guaranteed."
313+
"message": (
314+
"This flow run is missing infrastructure tracking information"
315+
" and cancellation cannot be guaranteed."
316+
)
309317
},
310318
)
311319
return
@@ -342,7 +350,7 @@ async def cancel_run(self, flow_run: FlowRun) -> None:
342350
self.logger.warning(f"{exc} Flow run cannot be cancelled by this agent.")
343351
except Exception:
344352
self.logger.exception(
345-
f"Encountered exception while killing infrastructure for flow run "
353+
"Encountered exception while killing infrastructure for flow run "
346354
f"'{flow_run.id}'. Flow run may not be cancelled."
347355
)
348356
# We will try again on generic exceptions
@@ -447,8 +455,9 @@ async def submit_run(self, flow_run: FlowRun) -> None:
447455
)
448456
except Exception as exc:
449457
self.logger.exception(
450-
"An error occured while setting the `infrastructure_pid` on "
451-
f"flow run {flow_run.id!r}. The flow run will not be cancellable."
458+
"An error occured while setting the `infrastructure_pid`"
459+
f" on flow run {flow_run.id!r}. The flow run will not be"
460+
" cancellable."
452461
)
453462

454463
self.logger.info(f"Completed submission of flow run '{flow_run.id}'")
@@ -507,7 +516,10 @@ async def _submit_run_and_capture_errors(
507516
if result.status_code != 0:
508517
await self._propose_crashed_state(
509518
flow_run,
510-
f"Flow run infrastructure exited with non-zero status code {result.status_code}.",
519+
(
520+
"Flow run infrastructure exited with non-zero status code"
521+
f" {result.status_code}."
522+
),
511523
)
512524

513525
return result
@@ -518,8 +530,10 @@ async def _propose_pending_state(self, flow_run: FlowRun) -> bool:
518530
state = await propose_state(self.client, Pending(), flow_run_id=flow_run.id)
519531
except Abort as exc:
520532
self.logger.info(
521-
f"Aborted submission of flow run '{flow_run.id}'. "
522-
f"Server sent an abort signal: {exc}",
533+
(
534+
f"Aborted submission of flow run '{flow_run.id}'. "
535+
f"Server sent an abort signal: {exc}"
536+
),
523537
)
524538
return False
525539
except Exception as exc:
@@ -531,8 +545,10 @@ async def _propose_pending_state(self, flow_run: FlowRun) -> bool:
531545

532546
if not state.is_pending():
533547
self.logger.info(
534-
f"Aborted submission of flow run '{flow_run.id}': "
535-
f"Server returned a non-pending state {state.type.value!r}",
548+
(
549+
f"Aborted submission of flow run '{flow_run.id}': "
550+
f"Server returned a non-pending state {state.type.value!r}"
551+
),
536552
)
537553
return False
538554

src/prefect/blocks/core.py

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,9 @@ def schema_extra(schema: Dict[str, Any], model: Type["Block"]):
202202
type_._to_block_schema_reference_dict(),
203203
]
204204
else:
205-
refs[
206-
field.name
207-
] = type_._to_block_schema_reference_dict()
205+
refs[field.name] = (
206+
type_._to_block_schema_reference_dict()
207+
)
208208

209209
def __init__(self, *args, **kwargs):
210210
super().__init__(*args, **kwargs)
@@ -716,7 +716,8 @@ class Custom(Block):
716716
)
717717
except prefect.exceptions.ObjectNotFound as e:
718718
raise ValueError(
719-
f"Unable to find block document named {block_document_name} for block type {block_type_slug}"
719+
f"Unable to find block document named {block_document_name} for block"
720+
f" type {block_type_slug}"
720721
) from e
721722

722723
try:
@@ -726,18 +727,20 @@ class Custom(Block):
726727
missing_fields = tuple(err["loc"][0] for err in e.errors())
727728
missing_block_data = {field: None for field in missing_fields}
728729
warnings.warn(
729-
f"Could not fully load {block_document_name!r} of block type {cls._block_type_slug!r} - "
730-
"this is likely because one or more required fields were added to the schema "
731-
f"for {cls.__name__!r} that did not exist on the class when this block was last saved. "
732-
f"Please specify values for new field(s): {listrepr(missing_fields)}, then "
733-
f'run `{cls.__name__}.save("{block_document_name}", overwrite=True)`, and '
734-
"load this block again before attempting to use it."
730+
f"Could not fully load {block_document_name!r} of block type"
731+
f" {cls._block_type_slug!r} - this is likely because one or more"
732+
" required fields were added to the schema for"
733+
f" {cls.__name__!r} that did not exist on the class when this block"
734+
" was last saved. Please specify values for new field(s):"
735+
f" {listrepr(missing_fields)}, then run"
736+
f' `{cls.__name__}.save("{block_document_name}", overwrite=True)`,'
737+
" and load this block again before attempting to use it."
735738
)
736739
return cls.construct(**block_document.data, **missing_block_data)
737740
raise RuntimeError(
738-
f"Unable to load {block_document_name!r} of block type {cls._block_type_slug!r} "
739-
"due to failed validation. To load without validation, try loading again "
740-
"with `validate=False`."
741+
f"Unable to load {block_document_name!r} of block type"
742+
f" {cls._block_type_slug!r} due to failed validation. To load without"
743+
" validation, try loading again with `validate=False`."
741744
) from e
742745

743746
@staticmethod
@@ -858,9 +861,9 @@ async def _save(
858861
)
859862
else:
860863
raise ValueError(
861-
"You are attempting to save values with a name that is already in "
862-
"use for this block type. If you would like to overwrite the values that are saved, "
863-
"then save with `overwrite=True`."
864+
"You are attempting to save values with a name that is already in"
865+
" use for this block type. If you would like to overwrite the"
866+
" values that are saved, then save with `overwrite=True`."
864867
) from err
865868

866869
# Update metadata on block instance for later use.

src/prefect/blocks/notifications.py

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ class AbstractAppriseNotificationBlock(NotificationBlock, ABC):
3333
An abstract class for sending notifications using Apprise.
3434
"""
3535

36-
notify_type: Literal[
37-
"prefect_default", "info", "success", "warning", "failure"
38-
] = Field(
39-
default=PrefectNotifyType.DEFAULT,
40-
description=(
41-
"The type of notification being performed; the prefect_default "
42-
"is a plain notification that does not attach an image."
43-
),
36+
notify_type: Literal["prefect_default", "info", "success", "warning", "failure"] = (
37+
Field(
38+
default=PrefectNotifyType.DEFAULT,
39+
description=(
40+
"The type of notification being performed; the prefect_default "
41+
"is a plain notification that does not attach an image."
42+
),
43+
)
4444
)
4545

4646
def _start_apprise_client(self, url: SecretStr):
@@ -129,7 +129,9 @@ class MicrosoftTeamsWebhook(AppriseNotificationBlock):
129129
...,
130130
title="Webhook URL",
131131
description="The Teams incoming webhook URL used to send notifications.",
132-
example="https://your-org.webhook.office.com/webhookb2/XXX/IncomingWebhook/YYY/ZZZ",
132+
example=(
133+
"https://your-org.webhook.office.com/webhookb2/XXX/IncomingWebhook/YYY/ZZZ"
134+
),
133135
)
134136

135137

@@ -324,7 +326,7 @@ class OpsgenieWebhook(AbstractAppriseNotificationBlock):
324326
apikey: SecretStr = Field(
325327
default=...,
326328
title="API Key",
327-
description=("The API Key associated with your Opsgenie account."),
329+
description="The API Key associated with your Opsgenie account.",
328330
)
329331

330332
target_user: Optional[List] = Field(
@@ -354,13 +356,19 @@ class OpsgenieWebhook(AbstractAppriseNotificationBlock):
354356

355357
tags: Optional[List] = Field(
356358
default=None,
357-
description="A comma-separated list of tags you can associate with your Opsgenie message.",
359+
description=(
360+
"A comma-separated list of tags you can associate with your Opsgenie"
361+
" message."
362+
),
358363
example='["tag1", "tag2"]',
359364
)
360365

361366
priority: Optional[str] = Field(
362367
default=3,
363-
description="The priority to associate with the message. It is on a scale between 1 (LOW) and 5 (EMERGENCY).",
368+
description=(
369+
"The priority to associate with the message. It is on a scale between 1"
370+
" (LOW) and 5 (EMERGENCY)."
371+
),
364372
)
365373

366374
alias: Optional[str] = Field(

0 commit comments

Comments
 (0)