Skip to content

Commit 0268882

Browse files
authored
Fix nits found by static analysis (#1545)
1 parent 50dc52d commit 0268882

File tree

7 files changed

+17
-21
lines changed

7 files changed

+17
-21
lines changed

.generator/src/generator/openapi.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,6 @@ def child_models(schema, alternative_name=None, seen=None, in_list=False):
217217
seen.add(name)
218218
yield name, schema
219219

220-
221220
if "enum" in schema:
222221
if name is None:
223222
raise ValueError(f"Schema {schema} has no name")
@@ -623,12 +622,12 @@ def format_server(server, path):
623622
url = server["url"] + path
624623
# replace potential path variables
625624
for variable, value in server_variables.items():
626-
url = url.replace("{" + variable + "}", value)
625+
url = url.replace(f"{{{variable}}}", value)
627626
# replace server variables if they were not replace before
628627
for variable in server["variables"]:
629628
if variable in server_variables:
630629
continue
631-
url = url.replace("{" + variable + "}", server["variables"][variable]["default"])
630+
url = url.replace(f"{{{variable}}}", server["variables"][variable]["default"])
632631
return url
633632

634633
server_variables = server_variables or {}

.generator/src/generator/templates/api_client.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ class ApiClient:
175175
elif isinstance(obj, (datetime, date)):
176176
if getattr(obj, "tzinfo", None) is not None:
177177
return obj.isoformat()
178-
return obj.strftime("%Y-%m-%dT%H:%M:%S") + obj.strftime(".%f")[:4] + "Z"
178+
return "{}Z".format(obj.strftime("%Y-%m-%dT%H:%M:%S.%f")[:-3])
179179
elif isinstance(obj, ModelSimple):
180180
return cls.sanitize_for_serialization(obj.value)
181181
elif isinstance(obj, (list, tuple)):

.generator/src/generator/templates/configuration.j2

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -361,8 +361,7 @@ class Configuration:
361361
prefix = self.api_key_prefix.get(identifier)
362362
if prefix:
363363
return "%s %s" % (prefix, key)
364-
else:
365-
return key
364+
return key
366365

367366
def get_basic_auth_token(self):
368367
"""Gets HTTP basic authentication header (string).
@@ -427,8 +426,8 @@ class Configuration:
427426
server = servers[index]
428427
except IndexError:
429428
raise ValueError(
430-
"Invalid index {0} when selecting the host settings. "
431-
"Must be less than {1}".format(index, len(servers))
429+
"Invalid index {} when selecting the host settings. "
430+
"Must be less than {}".format(index, len(servers))
432431
)
433432

434433
url = server["url"]
@@ -439,11 +438,11 @@ class Configuration:
439438

440439
if "enum_values" in variable and used_value not in variable["enum_values"]:
441440
raise ValueError(
442-
"The variable `{0}` in the host URL has invalid value "
443-
"{1}. Must be {2}.".format(variable_name, variables[variable_name], variable["enum_values"])
441+
"The variable `{}` in the host URL has invalid value "
442+
"{}. Must be {}.".format(variable_name, variables[variable_name], variable["enum_values"])
444443
)
445444

446-
url = url.replace("{" + variable_name + "}", used_value)
445+
{% raw %}url = url.replace(f"{{{variable_name}}}", used_value){%- endraw %}
447446

448447
return url
449448

.generator/src/generator/templates/model_utils.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1093,7 +1093,7 @@ def deserialize_model(model_data, model_class, path_to_item, check_type, configu
10931093
return model_class(model_data, **kw_args)
10941094
else:
10951095
return model_class(*model_data, **kw_args)
1096-
if isinstance(model_data, dict):
1096+
elif isinstance(model_data, dict):
10971097
kw_args.update(change_keys_js_to_python(model_data, model_class))
10981098
return model_class(**kw_args)
10991099
elif isinstance(model_data, PRIMITIVE_TYPES):

src/datadog_api_client/api_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ def sanitize_for_serialization(cls, obj):
176176
elif isinstance(obj, (datetime, date)):
177177
if getattr(obj, "tzinfo", None) is not None:
178178
return obj.isoformat()
179-
return obj.strftime("%Y-%m-%dT%H:%M:%S") + obj.strftime(".%f")[:4] + "Z"
179+
return "{}Z".format(obj.strftime("%Y-%m-%dT%H:%M:%S.%f")[:-3])
180180
elif isinstance(obj, ModelSimple):
181181
return cls.sanitize_for_serialization(obj.value)
182182
elif isinstance(obj, (list, tuple)):

src/datadog_api_client/configuration.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -390,8 +390,7 @@ def get_api_key_with_prefix(self, identifier, alias=None):
390390
prefix = self.api_key_prefix.get(identifier)
391391
if prefix:
392392
return "%s %s" % (prefix, key)
393-
else:
394-
return key
393+
return key
395394

396395
def get_basic_auth_token(self):
397396
"""Gets HTTP basic authentication header (string).
@@ -483,8 +482,7 @@ def get_host_from_settings(self, index, variables=None, servers=None):
483482
server = servers[index]
484483
except IndexError:
485484
raise ValueError(
486-
"Invalid index {0} when selecting the host settings. "
487-
"Must be less than {1}".format(index, len(servers))
485+
"Invalid index {} when selecting the host settings. " "Must be less than {}".format(index, len(servers))
488486
)
489487

490488
url = server["url"]
@@ -495,11 +493,11 @@ def get_host_from_settings(self, index, variables=None, servers=None):
495493

496494
if "enum_values" in variable and used_value not in variable["enum_values"]:
497495
raise ValueError(
498-
"The variable `{0}` in the host URL has invalid value "
499-
"{1}. Must be {2}.".format(variable_name, variables[variable_name], variable["enum_values"])
496+
"The variable `{}` in the host URL has invalid value "
497+
"{}. Must be {}.".format(variable_name, variables[variable_name], variable["enum_values"])
500498
)
501499

502-
url = url.replace("{" + variable_name + "}", used_value)
500+
url = url.replace(f"{{{variable_name}}}", used_value)
503501

504502
return url
505503

src/datadog_api_client/model_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1096,7 +1096,7 @@ def deserialize_model(model_data, model_class, path_to_item, check_type, configu
10961096
return model_class(model_data, **kw_args)
10971097
else:
10981098
return model_class(*model_data, **kw_args)
1099-
if isinstance(model_data, dict):
1099+
elif isinstance(model_data, dict):
11001100
kw_args.update(change_keys_js_to_python(model_data, model_class))
11011101
return model_class(**kw_args)
11021102
elif isinstance(model_data, PRIMITIVE_TYPES):

0 commit comments

Comments
 (0)