8000 remove key-existence checks against dict.keys() calls · localstack/localstack@0b631b1 · GitHub
[go: up one dir, main page]

Skip to content 8000

Commit 0b631b1

Browse files
committed
remove key-existence checks against dict.keys() calls
1 parent 32e05ec commit 0b631b1

File tree

11 files changed

+17
-17
lines changed

11 files changed

+17
-17
lines changed

localstack-core/localstack/services/apigateway/next_gen/execute_api/handlers/integration_request.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ def _validate_headers_mapping(headers: dict[str, str], integration_type: Integra
293293
if integration_type in {IntegrationType.AWS, IntegrationType.AWS_PROXY}:
294294
to_validate = ILLEGAL_INTEGRATION_REQUESTS_AWS
295295

296-
for header in headers.keys():
296+
for header in headers:
297297
if header.lower() in to_validate:
298298
LOG.debug(
299299
"Execution failed due to configuration error: %s header already present", header

localstack-core/localstack/services/cloudformation/engine/transformers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def apply_intrinsic_transformations(
7272
"""Resolve constructs using the 'Fn::Transform' intrinsic function."""
7373

7474
def _visit(obj, path, **_):
75-
if isinstance(obj, dict) and "Fn::Transform" in obj.keys():
75+
if isinstance(obj, dict) and "Fn::Transform" in obj:
7676
transform = (
7777
obj["Fn::Transform"]
7878
if isinstance(obj["Fn::Transform"], dict)

localstack-core/localstack/services/cloudwatch/alarm_scheduler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,13 @@ def restart_existing_alarms(self) -> None:
105105
def _is_alarm_supported(self, alarm_details: MetricAlarm) -> bool:
106106
required_parameters = ["Period", "Statistic", "MetricName", "Threshold"]
107107
for param in required_parameters:
108-
if param not in alarm_details.keys():
108+
if param not in alarm_details:
109109
LOG.debug(
110110
"Currently only simple MetricAlarm are supported. Alarm is missing '%s'. ExtendedStatistic is not yet supported.",
111111
param,
112112
)
113113
return False
114-
if alarm_details["ComparisonOperator"] not in COMPARISON_OPS.keys():
114+
if alarm_details["ComparisonOperator"] not in COMPARISON_OPS:
115115
LOG.debug(
116116
"ComparisonOperator '%s' not yet supported.",
117117
alarm_details["ComparisonOperator"],

localstack-core/localstack/services/dynamodb/provider.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,7 @@ def update_table(
823823

824824
match key:
825825
case "Create":
826-
if target_region in replicas.keys():
826+
if target_region in replicas:
827827
raise ValidationException(
828828
f"Failed to create a the new replica of table with name: '{table_name}' because one or more replicas already existed as tables."
829829
)

localstack-core/localstack/services/events/provider.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ def create_event_bus(
214214
region = context.region
215215
account_id = context.account_id
216216
store = self.get_store(region, account_id)
217-
if name in store.event_buses.keys():
217+
if name in store.event_buses:
218218
raise ResourceAlreadyExistsException(f"Event bus {name} already exists.")
219219
event_bus_service = self.create_event_bus_service(
220220
name, region, account_id, event_source_name, tags
@@ -591,7 +591,7 @@ def create_archive(
591591
region = context.region
592592
account_id = context.account_id
593593
store = self.get_store(region, account_id)
594-
if archive_name in store.archives.keys():
594+
if archive_name in store.archives:
595595
raise ResourceAlreadyExistsException(f"Archive {archive_name} already exists.")
596596
self._check_event_bus_exists(event_source_arn, store)
597597
archive_service = self.create_archiv F438 e_service(
@@ -821,7 +821,7 @@ def start_replay(
821821
region = context.region
822822
account_id = context.account_id
823823
store = self.get_store(region, account_id)
824-
if replay_name in store.replays.keys():
824+
if replay_name in store.replays:
825825
raise ResourceAlreadyExistsException(f"Replay {replay_name} already exists.")
826826
self._validate_replay_time(event_start_time, event_end_time)
827827
if event_source_arn not in self._archive_service_store:
@@ -912,7 +912,7 @@ def get_store(self, region: str, account_id: str) -> EventsStore:
912912
store = events_store[account_id][region]
913913
# create default event bus for account region on first call
914914
default_event_bus_name = "default"
915-
if default_event_bus_name not in store.event_buses.keys():
915+
if default_event_bus_name not in store.event_buses:
916916
event_bus_service = self.create_event_bus_service(
917917
default_event_bus_name, region, account_id, None, None
918918
)
@@ -1159,7 +1159,7 @@ def _validate_replay_destination(
11591159
archive_service = self._archive_service_store[event_source_arn]
11601160
if destination_arn := destination.get("Arn"):
11611161
if destination_arn != archive_service.archive.event_source_arn:
1162-
if destination_arn in self._event_bus_services_store.keys():
1162+
if destination_arn in self._event_bus_services_store:
11631163
raise ValidationException(
11641164
"Parameter Destination.Arn is not valid. Reason: Cross event bus replay is not permitted."
11651165
)

localstack-core/localstack/services/secretsmanager/provider.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ def moto_smb_create_secret(fn, self, name, *args, **kwargs):
488488
if secret is not None and secret.deleted_date is not None:
489489
raise InvalidRequestException(AWS_INVALID_REQUEST_MESSAGE_CREATE_WITH_SCHEDULED_DELETION)
490490

491-
if name in self.secrets.keys():
491+
if name in self.secrets:
492492
raise ResourceExistsException(
493493
f"The operation failed because the secret {name} already exists."
494494
)

localstack-core/localstack/services/sqs/provider.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,7 @@ def _require_queue(
802802
"""
803803
store = SqsProvider.get_store(account_id, region_name)
804804
with _STORE_LOCK:
805-
if name not in store.queues.keys():
805+
if name not in store.queues:
806806
if is_query:
807807
message = "The specified queue does not exist for this wsdl version."
808808
else:

localstack-core/localstack/services/stepfunctions/resource_providers/aws_stepfunctions_statemachine.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ def _apply_substitutions(definition: str, substitutions: dict[str, str]) -> str:
224224
result = definition
225225
for token in tokens:
226226
raw_token = token[2:-1] # strip ${ and }
227-
if raw_token not in substitutions.keys():
227+
if raw_token not in substitutions:
228228
raise
229229
result = result.replace(token, substitutions[raw_token])
230230

localstack-core/localstack/services/stores.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def __set_name__(self, owner, name):
9494
def __get__(self, obj: BaseStoreType, objtype=None) -> Any:
9595
self._check_region_store_association(obj)
9696

97-
if self.name not in obj._global.keys():
97+
if self.name not in obj._global:
9898
if isinstance(self.default, Callable):
9999
obj._global[self.name] = self.default()
100100
else:
@@ -135,7 +135,7 @@ def __set_name__(self, ow B3A8 ner, name):
135135
def __get__(self, obj: BaseStoreType, objtype=None) -> Any:
136136
self._check_account_store_association(obj)
137137

138-
if self.name not in obj._universal.keys():
138+
if self.name not in obj._universal:
139139
if isinstance(self.default, Callable):
140140
obj._universal[self.name] = self.default()
141141
else:

localstack-core/localstack/utils/aws/message_forwarding.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ def add_target_http_parameters(http_parameters: Dict, endpoint: str, headers: Di
298298
endpoint = add_query_params_to_url(endpoint, query_params)
299299

300300
target_headers = http_parameters.get("HeaderParameters", {})
301-
for target_header in target_headers.keys():
301+
for target_header in target_headers:
302302
if target_header not in headers:
303303
headers.update({target_header: target_headers.get(target_header)})
304304

0 commit comments

Comments
 (0)
0