Skip to content

Commit b174939

Browse files
committed
flynt/pyupgrade changes
1 parent 20810e8 commit b174939

File tree

5 files changed

+15
-26
lines changed

5 files changed

+15
-26
lines changed

ecs_logging/_stdlib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def __init__(
111111
if validate is not None:
112112
# validate was introduced in py3.8 so we need to only provide it if the user provided it
113113
_kwargs["validate"] = validate
114-
super(StdlibFormatter, self).__init__( # type: ignore[call-arg]
114+
super().__init__( # type: ignore[call-arg]
115115
fmt=fmt, datefmt=datefmt, style=style, **_kwargs
116116
)
117117

ecs_logging/_utils.py

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,15 @@ def flatten_dict(value):
6262
for key, val in value.items():
6363
if not isinstance(val, collections_abc.Mapping):
6464
if key in top_level:
65-
raise ValueError(
66-
"Duplicate entry for '%s' with different nesting" % key
67-
)
65+
raise ValueError(f"Duplicate entry for '{key}' with different nesting")
6866
top_level[key] = val
6967
else:
7068
val = flatten_dict(val)
7169
for vkey, vval in val.items():
72-
vkey = "%s.%s" % (key, vkey)
70+
vkey = f"{key}.{vkey}"
7371
if vkey in top_level:
7472
raise ValueError(
75-
"Duplicate entry for '%s' with different nesting" % vkey
73+
f"Duplicate entry for '{vkey}' with different nesting"
7674
)
7775
top_level[vkey] = vval
7876

@@ -163,16 +161,9 @@ def json_dumps(value):
163161
# Need to call json.dumps() on values just in
164162
# case the given values aren't strings (even though
165163
# they should be according to the spec)
166-
ordered_json = ",".join(
167-
'"%s":%s'
168-
% (
169-
k,
170-
json_dumps(v),
171-
)
172-
for k, v in ordered_fields
173-
)
164+
ordered_json = ",".join(f'"{k}":{json_dumps(v)}' for k, v in ordered_fields)
174165
if value:
175-
return "{%s,%s" % (
166+
return "{{{},{}".format(
176167
ordered_json,
177168
json_dumps(value)[1:],
178169
)

tests/conftest.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@ class ValidationError(Exception):
3232

3333
@pytest.fixture
3434
def spec_validator():
35-
with open(
36-
os.path.join(os.path.dirname(__file__), "resources", "spec.json"), "r"
37-
) as fh:
35+
with open(os.path.join(os.path.dirname(__file__), "resources", "spec.json")) as fh:
3836
spec = json.load(fh)
3937

4038
def validator(data_json):
@@ -59,11 +57,11 @@ def validator(data_json):
5957
if subval:
6058
found = True
6159
if not found:
62-
raise ValidationError("Missing required key {}".format(k))
60+
raise ValidationError(f"Missing required key {k}")
6361
if k in data:
6462
if v["type"] == "string" and not isinstance(data[k], str):
6563
raise ValidationError(
66-
"Value {0} for key {1} should be string, is {2}".format(
64+
"Value {} for key {} should be string, is {}".format(
6765
data[k], k, type(data[k])
6866
)
6967
)
@@ -72,12 +70,12 @@ def validator(data_json):
7270
datetime.datetime.strptime(data[k], "%Y-%m-%dT%H:%M:%S.%fZ")
7371
except ValueError:
7472
raise ValidationError(
75-
"Value {0} for key {1} doesn't parse as an ISO datetime".format(
73+
"Value {} for key {} doesn't parse as an ISO datetime".format(
7674
data[k], k
7775
)
7876
)
7977
if v.get("index") and list(data.keys())[v.get("index")] != k:
80-
raise ValidationError("Key {0} is not at index {1}".format(k, index))
78+
raise ValidationError(f"Key {k} is not at index {index}")
8179

8280
return data_json
8381

tests/test_stdlib_formatter.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
import logging
1919
import logging.config
20-
import mock
20+
from unittest import mock
2121
import pytest
2222
import json
2323
import time
@@ -29,7 +29,7 @@
2929

3030
@pytest.fixture(scope="function")
3131
def logger():
32-
return logging.getLogger("test-logger-%f-%f" % (time.time(), random.random()))
32+
return logging.getLogger(f"test-logger-{time.time():f}-{random.random():f}")
3333

3434

3535
def make_record():
@@ -74,7 +74,7 @@ def test_extra_global_is_merged(spec_validator):
7474
def test_can_be_overridden(spec_validator):
7575
class CustomFormatter(ecs_logging.StdlibFormatter):
7676
def format_to_ecs(self, record):
77-
ecs_dict = super(CustomFormatter, self).format_to_ecs(record)
77+
ecs_dict = super().format_to_ecs(record)
7878
ecs_dict["custom"] = "field"
7979
return ecs_dict
8080

tests/test_structlog_formatter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
import ecs_logging
1919
import structlog
20-
import mock
20+
from unittest import mock
2121
from io import StringIO
2222

2323
import pytest

0 commit comments

Comments
 (0)