Skip to content

Commit 7538bbd

Browse files
cclausscdkinitalagluck
authored
[MAINTENANCE] Upgrade to modern Python syntax (great-expectations#3068)
* Upgrade to modern Python syntax * black . Co-authored-by: Chetan Kini <[email protected]> Co-authored-by: talagluck <[email protected]>
1 parent 59dce01 commit 7538bbd

File tree

76 files changed

+270
-310
lines changed

Some content is hidden

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

76 files changed

+270
-310
lines changed

assets/scripts/build_gallery.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,7 @@ def build_gallery(
127127
logger.info("Loading great_expectations library.")
128128
installed_packages = pkg_resources.working_set
129129
installed_packages_names = [i.key for i in installed_packages]
130-
installed_packages_txt = sorted(
131-
[f"{i.key}=={i.version}" for i in installed_packages]
132-
)
130+
installed_packages_txt = sorted(f"{i.key}=={i.version}" for i in installed_packages)
133131
logger.debug(f"Found the following packages: {installed_packages_txt}")
134132

135133
import great_expectations

docs_rtd/example_code/custom_renderer.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def _get_bullet_list_content_block(cls, header="", subheader="", col=12):
5555
),
5656
],
5757
"styling": {
58-
"classes": ["col-{}".format(col)],
58+
"classes": [f"col-{col}"],
5959
"styles": {"margin-top": "20px"},
6060
},
6161
}
@@ -80,7 +80,7 @@ def _get_table_content_block(cls, header="", subheader="", col=12):
8080
["row_2", "crayon", "derby"],
8181
],
8282
"styling": {
83-
"classes": ["col-{}".format(col), "table-responsive"],
83+
"classes": [f"col-{col}", "table-responsive"],
8484
"styles": {"margin-top": "20px"},
8585
"body": {"classes": ["table", "table-sm"]},
8686
},
@@ -107,7 +107,7 @@ def _get_graph_content_block(cls, header="", subheader="", col=12):
107107
"subheader": subheader,
108108
"graph": chart,
109109
"styling": {
110-
"classes": ["col-{}".format(col)],
110+
"classes": [f"col-{col}"],
111111
"styles": {"margin-top": "20px"},
112112
},
113113
}
@@ -188,7 +188,7 @@ def _get_value_list_content_block(cls, header="", subheader="", col=12):
188188
}
189189
for value in ["Andrew", "Elijah", "Matthew", "Cindy", "Pam"]
190190
],
191-
"styling": {"classes": ["col-{}".format(col)]},
191+
"styling": {"classes": [f"col-{col}"]},
192192
}
193193
)
194194

great_expectations/_version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False, env=
9494
return None, None
9595
else:
9696
if verbose:
97-
print("unable to find command, tried {}".format(commands))
97+
print(f"unable to find command, tried {commands}")
9898
return None, None
9999
stdout = p.communicate()[0].strip()
100100
if sys.version_info[0] >= 3:

great_expectations/checkpoint/checkpoint.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ def _run_default_validation_operator(
514514
run_name = datetime.datetime.now(datetime.timezone.utc).strftime(
515515
"%Y%m%dT%H%M%S.%fZ"
516516
)
517-
logger.info("Setting run_name to: {}".format(run_name))
517+
logger.info(f"Setting run_name to: {run_name}")
518518

519519
default_validation_operator = ActionListValidationOperator(
520520
data_context=self.data_context,

great_expectations/cli/batch_request.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def select_data_connector_name(
134134
)
135135
choices: str = "\n".join(
136136
[
137-
" {}. {}".format(i, data_connector_name)
137+
f" {i}. {data_connector_name}"
138138
for i, data_connector_name in enumerate(data_connector_names, 1)
139139
]
140140
)
@@ -167,15 +167,12 @@ def _get_data_asset_name_from_data_connector(
167167
key=lambda x: x,
168168
)
169169
available_data_asset_names_str: List[str] = [
170-
"{}".format(name) for name in available_data_asset_names
170+
f"{name}" for name in available_data_asset_names
171171
]
172172

173173
data_asset_names_to_display: List[str] = available_data_asset_names_str[:50]
174174
choices: str = "\n".join(
175-
[
176-
" {}. {}".format(i, name)
177-
for i, name in enumerate(data_asset_names_to_display, 1)
178-
]
175+
[f" {i}. {name}" for i, name in enumerate(data_asset_names_to_display, 1)]
179176
)
180177
prompt: str = msg_prompt_enter_data_asset_name + choices + "\n"
181178
data_asset_name_selection: str = click.prompt(prompt, show_default=False)

great_expectations/cli/build_docs.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ def build_docs(
2222

2323
msg: str = "\nThe following Data Docs sites will be built:\n\n"
2424
for site_name, index_page_locator_info in index_page_locator_infos.items():
25-
msg += " - <cyan>{}:</cyan> ".format(site_name)
26-
msg += "{}\n".format(index_page_locator_info)
25+
msg += f" - <cyan>{site_name}:</cyan> "
26+
msg += f"{index_page_locator_info}\n"
2727

2828
cli_message(msg)
2929
if not assume_yes:

great_expectations/cli/init.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,15 @@ def init(ctx, usage_stats):
8080
exit(0)
8181

8282
except (DataContextError, DatasourceInitializationError) as e:
83-
cli_message("<red>{}</red>".format(e.message))
83+
cli_message(f"<red>{e.message}</red>")
8484
sys.exit(1)
8585

8686
try:
8787
DataContext.create(target_directory, usage_statistics_enabled=usage_stats)
8888
cli_message(ONBOARDING_COMPLETE)
8989

9090
except DataContextError as e:
91-
cli_message("<red>{}</red>".format(e.message))
91+
cli_message(f"<red>{e.message}</red>")
9292
# TODO ensure this is covered by a test
9393
exit(5)
9494
else:
@@ -106,7 +106,7 @@ def init(ctx, usage_stats):
106106
)
107107
except DataContextError as e:
108108
# TODO ensure this is covered by a test
109-
cli_message("<red>{}</red>".format(e))
109+
cli_message(f"<red>{e}</red>")
110110

111111
cli_message(SECTION_SEPARATOR)
112112
cli_message(READY_FOR_CUSTOMIZATION)

great_expectations/cli/project.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def project_check_config(ctx):
3232
)
3333
if not is_config_ok:
3434
cli_message("Unfortunately, your config appears to be invalid:\n")
35-
cli_message("<red>{}</red>".format(error_message))
35+
cli_message(f"<red>{error_message}</red>")
3636
sys.exit(1)
3737

3838
cli_message("<green>Your config file appears valid!</green>")

great_expectations/cli/suite.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ def _suite_new_workflow(
332332
OSError,
333333
SQLAlchemyError,
334334
) as e:
335-
cli_message(string="<red>{}</red>".format(e))
335+
cli_message(string=f"<red>{e}</red>")
336336
toolkit.send_usage_message(
337337
data_context=context, event=usage_event, success=False
338338
)
@@ -619,7 +619,7 @@ def _suite_edit_workflow(
619619
batch_request=batch_request,
620620
)
621621

622-
notebook_name: str = "edit_{}.ipynb".format(expectation_suite_name)
622+
notebook_name: str = f"edit_{expectation_suite_name}.ipynb"
623623
notebook_path: str = _get_notebook_path(context, notebook_name)
624624

625625
if profile:
@@ -675,7 +675,7 @@ def _suite_edit_workflow(
675675
OSError,
676676
SQLAlchemyError,
677677
) as e:
678-
cli_message(string="<red>{}</red>".format(e))
678+
cli_message(string=f"<red>{e}</red>")
679679
if not suppress_usage_message:
680680
toolkit.send_usage_message(
681681
data_context=context, event=usage_event, success=False

great_expectations/cli/toolkit.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ def select_datasource(
386386
else:
387387
choices: str = "\n".join(
388388
[
389-
" {}. {}".format(i, data_source.name)
389+
f" {i}. {data_source.name}"
390390
for i, data_source in enumerate(data_sources, 1)
391391
]
392392
)
@@ -462,13 +462,13 @@ def load_data_context_with_error_handling(
462462
from_cli_upgrade_command=from_cli_upgrade_command,
463463
)
464464
else:
465-
cli_message(string="<red>{}</red>".format(err.message))
465+
cli_message(string=f"<red>{err.message}</red>")
466466
sys.exit(1)
467467
except (
468468
ge_exceptions.ConfigNotFoundError,
469469
ge_exceptions.InvalidConfigError,
470470
) as err:
471-
cli_message(string="<red>{}</red>".format(err.message))
471+
cli_message(string=f"<red>{err.message}</red>")
472472
sys.exit(1)
473473
except ge_exceptions.PluginModuleNotFoundError as err:
474474
cli_message(string=err.cli_colored_message)
@@ -885,7 +885,7 @@ def get_batch_request_from_json_file(
885885
cli_message(
886886
string="<red>Please check that your batch_request is valid and is able to load a batch.</red>"
887887
)
888-
cli_message(string="<red>{}</red>".format(e))
888+
cli_message(string=f"<red>{e}</red>")
889889
if not suppress_usage_message:
890890
send_usage_message(
891891
data_context=data_context, event=usage_event, success=False

great_expectations/cli/v012/datasource.py

+12-20
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,7 @@ def datasource_new(directory):
9090
datasource_name, data_source_type = add_datasource(context)
9191

9292
if datasource_name:
93-
cli_message(
94-
"A new datasource '{}' was added to your project.".format(datasource_name)
95-
)
93+
cli_message(f"A new datasource '{datasource_name}' was added to your project.")
9694
toolkit.send_usage_message(
9795
data_context=context, event="cli.datasource.new", success=True
9896
)
@@ -118,9 +116,7 @@ def delete_datasource(directory, datasource):
118116
context.delete_datasource(datasource)
119117
except ValueError:
120118
cli_message(
121-
"<red>{}</red>".format(
122-
"Datasource {} could not be found.".format(datasource)
123-
)
119+
"<red>{}</red>".format(f"Datasource {datasource} could not be found.")
124120
)
125121
sys.exit(1)
126122
try:
@@ -404,7 +400,7 @@ def _add_pandas_datasource(
404400
errors = DatasourceConfigSchema().validate(configuration)
405401
if len(errors) != 0:
406402
raise ge_exceptions.GreatExpectationsError(
407-
"Invalid Datasource configuration: {:s}".format(errors)
403+
f"Invalid Datasource configuration: {errors:s}"
408404
)
409405

410406
cli_message(
@@ -457,7 +453,7 @@ def _add_sqlalchemy_datasource(context, prompt_for_datasource_name=True):
457453
success=True,
458454
)
459455

460-
datasource_name = "my_{}_db".format(selected_database.value.lower())
456+
datasource_name = f"my_{selected_database.value.lower()}_db"
461457
if selected_database == SupportedDatabases.OTHER:
462458
datasource_name = "my_database"
463459
if prompt_for_datasource_name:
@@ -533,7 +529,7 @@ def _add_sqlalchemy_datasource(context, prompt_for_datasource_name=True):
533529
errors = DatasourceConfigSchema().validate(configuration)
534530
if len(errors) != 0:
535531
raise ge_exceptions.GreatExpectationsError(
536-
"Invalid Datasource configuration: {:s}".format(errors)
532+
f"Invalid Datasource configuration: {errors:s}"
537533
)
538534

539535
cli_message(
@@ -898,7 +894,7 @@ def _add_spark_datasource(
898894
errors = DatasourceConfigSchema().validate(configuration)
899895
if len(errors) != 0:
900896
raise ge_exceptions.GreatExpectationsError(
901-
"Invalid Datasource configuration: {:s}".format(errors)
897+
f"Invalid Datasource configuration: {errors:s}"
902898
)
903899

904900
cli_message(
@@ -941,7 +937,7 @@ def select_batch_kwargs_generator(
941937
generator_names = list(available_data_asset_names_by_generator.keys())
942938
choices = "\n".join(
943939
[
944-
" {}. {}".format(i, generator_name)
940+
f" {i}. {generator_name}"
945941
for i, generator_name in enumerate(generator_names, 1)
946942
]
947943
)
@@ -1107,14 +1103,13 @@ def _get_batch_kwargs_from_generator_or_from_file_path(
11071103
generator.get_available_data_asset_names()["names"], key=lambda x: x[0]
11081104
)
11091105
available_data_asset_names_str = [
1110-
"{} ({})".format(name[0], name[1])
1111-
for name in available_data_asset_names
1106+
f"{name[0]} ({name[1]})" for name in available_data_asset_names
11121107
]
11131108

11141109
data_asset_names_to_display = available_data_asset_names_str[:50]
11151110
choices = "\n".join(
11161111
[
1117-
" {}. {}".format(i, name)
1112+
f" {i}. {name}"
11181113
for i, name in enumerate(data_asset_names_to_display, 1)
11191114
]
11201115
)
@@ -1294,14 +1289,13 @@ def _get_batch_kwargs_for_sqlalchemy_datasource(
12941289
temp_generator.get_available_data_asset_names()["names"]
12951290
)
12961291
available_data_asset_names_str = [
1297-
"{} ({})".format(name[0], name[1])
1298-
for name in available_data_asset_names
1292+
f"{name[0]} ({name[1]})" for name in available_data_asset_names
12991293
]
13001294

13011295
data_asset_names_to_display = available_data_asset_names_str
13021296
choices = "\n".join(
13031297
[
1304-
" {}. {}".format(i, name)
1298+
f" {i}. {name}"
13051299
for i, name in enumerate(data_asset_names_to_display, 1)
13061300
]
13071301
)
@@ -1628,9 +1622,7 @@ def profile_datasource(
16281622
Which database backend are you using?
16291623
{}
16301624
""".format(
1631-
"\n".join(
1632-
[" {}. {}".format(i, db.value) for i, db in enumerate(SupportedDatabases, 1)]
1633-
)
1625+
"\n".join([f" {i}. {db.value}" for i, db in enumerate(SupportedDatabases, 1)])
16341626
)
16351627

16361628
msg_prompt_filesys_enter_base_path = """

great_expectations/cli/v012/docs.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,8 @@ def build_docs(context, site_name=None, view=True, assume_yes=False):
144144

145145
msg = "\nThe following Data Docs sites will be built:\n\n"
146146
for site_name, index_page_locator_info in index_page_locator_infos.items():
147-
msg += " - <cyan>{}:</cyan> ".format(site_name)
148-
msg += "{}\n".format(index_page_locator_info)
147+
msg += f" - <cyan>{site_name}:</cyan> "
148+
msg += f"{index_page_locator_info}\n"
149149

150150
cli_message(msg)
151151
if not assume_yes:

great_expectations/cli/v012/init.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def init(target_directory, view, usage_stats):
7676
# Ensure the context can be instantiated
7777
cli_message(PROJECT_IS_COMPLETE)
7878
except (DataContextError, DatasourceInitializationError) as e:
79-
cli_message("<red>{}</red>".format(e.message))
79+
cli_message(f"<red>{e.message}</red>")
8080
sys.exit(1)
8181

8282
try:
@@ -88,7 +88,7 @@ def init(target_directory, view, usage_stats):
8888
# cli_message(SETUP_SUCCESS)
8989
# exit(0)
9090
except DataContextError as e:
91-
cli_message("<red>{}</red>".format(e.message))
91+
cli_message(f"<red>{e.message}</red>")
9292
# TODO ensure this is covered by a test
9393
exit(5)
9494
else:
@@ -106,7 +106,7 @@ def init(target_directory, view, usage_stats):
106106
)
107107
except DataContextError as e:
108108
# TODO ensure this is covered by a test
109-
cli_message("<red>{}</red>".format(e))
109+
cli_message(f"<red>{e}</red>")
110110

111111
try:
112112
# if expectations exist, offer to build docs
@@ -188,7 +188,7 @@ def init(target_directory, view, usage_stats):
188188
OSError,
189189
SQLAlchemyError,
190190
) as e:
191-
cli_message("<red>{}</red>".format(e))
191+
cli_message(f"<red>{e}</red>")
192192
sys.exit(1)
193193

194194

great_expectations/cli/v012/project.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def project_check_config(directory):
3434
)
3535
if not is_config_ok:
3636
cli_message("Unfortunately, your config appears to be invalid:\n")
37-
cli_message("<red>{}</red>".format(error_message))
37+
cli_message(f"<red>{error_message}</red>")
3838
sys.exit(1)
3939

4040
cli_message("<green>Your config file appears valid!</green>")

great_expectations/cli/v012/store.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def store_list(directory):
3333
elif len(stores) == 1:
3434
list_intro_string = "1 Store found:"
3535
else:
36-
list_intro_string = "{} Stores found:".format(len(stores))
36+
list_intro_string = f"{len(stores)} Stores found:"
3737

3838
cli_message(list_intro_string)
3939

0 commit comments

Comments
 (0)