Skip to content

Commit

Permalink
Add flake8-comprehensions
Browse files Browse the repository at this point in the history
  • Loading branch information
replaceafill committed Sep 20, 2023
1 parent fd79346 commit dc7c9a0
Show file tree
Hide file tree
Showing 13 changed files with 40 additions and 46 deletions.
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ repos:
- id: flake8
additional_dependencies:
- flake8-bugbear==23.9.16
- flake8-comprehensions==3.14.0
2 changes: 1 addition & 1 deletion src/MCPClient/lib/clientScripts/json_metadata_to_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def fetch_keys(objects):
# Column order is important so the output is consistent.
# "filename" and "parts" must be column 0.
# (They are mutually exclusive.)
keys = sorted(list(keys))
keys = sorted(keys)
if "filename" in keys:
keys.remove("filename")
keys.insert(0, "filename")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ def getItemCountType(structMap):
"""
divs_with_dmdsecs = structMap.findall(".//mets:div[@DMDID]", namespaces=ns.NSMAP)
# If any are TYPE Directory, then it is compound
if any([e.get("TYPE") == "Directory" for e in divs_with_dmdsecs]):
if any(e.get("TYPE") == "Directory" for e in divs_with_dmdsecs):
# If all are TYPE Directory then it is bulk
if all([e.get("TYPE") == "Directory" for e in divs_with_dmdsecs]):
if all(e.get("TYPE") == "Directory" for e in divs_with_dmdsecs):
return "compound-dirs"
else:
return "compound-files"
Expand Down
2 changes: 1 addition & 1 deletion src/MCPClient/tests/test_create_aip_mets.py
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,7 @@ def generate_aip_mets_v2_state(self):
)
self.state = create_mets_v2.MetsState()
self.state.globalStructMapCounter = random.choice(
[x for x in range(arbitrary_max_structmaps)]
list(range(arbitrary_max_structmaps))
)
self.structmap_div_element = create_mets_v2.createFileSec(
job=Job("stub", "stub", []),
Expand Down
2 changes: 1 addition & 1 deletion src/MCPClient/tests/test_load_premis_events_from_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def test_get_premis_element_children_identifiers(mocker):
"params",
[
{"original_name": "name", "expected_original_name": "name"},
{"original_name": tuple(), "expected_original_name": ""},
{"original_name": (), "expected_original_name": ""},
],
ids=["original_name_as_string", "original_name_as_empty_string"],
)
Expand Down
2 changes: 1 addition & 1 deletion src/MCPServer/lib/server/packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@ def set_variable(self, key, value, chain_link_id):
unittype=self.UNIT_VARIABLE_TYPE,
unituuid=self.uuid,
variable=key,
defaults=dict(variablevalue=value, microservicechainlink=chain_link_id),
defaults={"variablevalue": value, "microservicechainlink": chain_link_id},
)
if created:
message = "New UnitVariable %s created for %s: %s (MSCL: %s)"
Expand Down
12 changes: 6 additions & 6 deletions src/archivematicaCommon/lib/bindpid.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,12 +316,12 @@ def _render_request_body(argsdict, resolve_url, qualified_resolve_urls):
"""
return _render_template(
argsdict["pid_request_body_template"],
dict(
naming_authority=argsdict["naming_authority"],
pid=argsdict["desired_pid"],
base_resolve_url=resolve_url,
qualified_resolve_urls=qualified_resolve_urls,
),
{
"naming_authority": argsdict["naming_authority"],
"pid": argsdict["desired_pid"],
"base_resolve_url": resolve_url,
"qualified_resolve_urls": qualified_resolve_urls,
},
).encode("utf8")


Expand Down
30 changes: 15 additions & 15 deletions src/archivematicaCommon/lib/email_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,27 +59,27 @@ def get_settings(config):
This should be invoked from a Django settings module and the result merged
into the globals() dict.
"""
settings = dict(
settings = {
# Which backend to use?
EMAIL_BACKEND=config.get("email_backend"),
"EMAIL_BACKEND": config.get("email_backend"),
# File Backend
# See https://docs.djangoproject.com/en/dev/topics/email/#file-backend
EMAIL_FILE_PATH=config.get("email_file_path"),
"EMAIL_FILE_PATH": config.get("email_file_path"),
# SMTP Backend
# See https://docs.djangoproject.com/en/dev/topics/email/#smtp-backend
EMAIL_HOST=config.get("email_host"),
EMAIL_HOST_PASSWORD=config.get("email_host_password"),
EMAIL_HOST_USER=config.get("email_host_user"),
EMAIL_PORT=config.get("email_port"),
EMAIL_SSL_CERTFILE=config.get("email_ssl_certfile"),
EMAIL_SSL_KEYFILE=config.get("email_ssl_keyfile"),
EMAIL_USE_SSL=config.get("email_use_ssl"),
EMAIL_USE_TLS=config.get("email_use_tls"),
"EMAIL_HOST": config.get("email_host"),
"EMAIL_HOST_PASSWORD": config.get("email_host_password"),
"EMAIL_HOST_USER": config.get("email_host_user"),
"EMAIL_PORT": config.get("email_port"),
"EMAIL_SSL_CERTFILE": config.get("email_ssl_certfile"),
"EMAIL_SSL_KEYFILE": config.get("email_ssl_keyfile"),
"EMAIL_USE_SSL": config.get("email_use_ssl"),
"EMAIL_USE_TLS": config.get("email_use_tls"),
# General settings, not backend-specific
DEFAULT_FROM_EMAIL=config.get("default_from_email"),
EMAIL_SUBJECT_PREFIX=config.get("email_subject_prefix"),
EMAIL_TIMEOUT=config.get("email_timeout", None),
)
"DEFAULT_FROM_EMAIL": config.get("default_from_email"),
"EMAIL_SUBJECT_PREFIX": config.get("email_subject_prefix"),
"EMAIL_TIMEOUT": config.get("email_timeout", None),
}

settings["SERVER_EMAIL"] = config.get("server_email", settings["EMAIL_HOST_USER"])
return settings
2 changes: 1 addition & 1 deletion src/dashboard/src/components/administration/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ def general(request):
)

forms = (general_form, storage_form, checksum_form)
if all([form.is_valid() for form in forms]):
if all(form.is_valid() for form in forms):
for item in forms:
item.save()
messages.info(request, _("Saved."))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ def test_search_as_csv(mocker, amsetup, admin_client, tmp_path):
response.get(CONTENT_DISPOSITION) == 'attachment; filename="test-filename.csv"'
)

streamed_content = b"".join([content for content in response.streaming_content])
streamed_content = b"".join(list(response.streaming_content))
csv_file = StringIO(streamed_content.decode("utf8"))

assert csv_file.read() == (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -522,13 +522,11 @@ def _import_self_describing_transfer(
"""
transfer, created = Transfer.objects.get_or_create(
uuid=transfer_uuid,
defaults=dict(
type="Standard",
diruuids=False,
currentlocation="%sharedPath%www/AIPsStore/transferBacklog/originals/"
+ str(transfer_dir.name)
+ "/",
),
defaults={
"type": "Standard",
"diruuids": False,
"currentlocation": f"%sharedPath%www/AIPsStore/transferBacklog/originals/{transfer_dir.name}/",
},
)

# The transfer did not exist, we need to populate everything else.
Expand Down
9 changes: 3 additions & 6 deletions src/dashboard/src/main/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,9 @@ def get_dict(self, scope):
{u'foo': u'bar'}
"""
return {
key: value
for (key, value) in self.get_queryset()
.filter(scope=scope)
.values_list("name", "value")
}
return dict(
self.get_queryset().filter(scope=scope).values_list("name", "value")
)

def set_dict(self, scope, items):
"""
Expand Down
6 changes: 2 additions & 4 deletions src/dashboard/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,10 +516,8 @@ def test_list_processing_configs(self):
assert len(processing_configs) == 2
expected_names = sorted(["default", "automated"])
assert all(
[
actual == expected
for actual, expected in zip(processing_configs, expected_names)
]
actual == expected
for actual, expected in zip(processing_configs, expected_names)
)

def test_get_existing_processing_config(self):
Expand Down

0 comments on commit dc7c9a0

Please sign in to comment.