Skip to content

Commit 9a19a98

Browse files
committed
Run flynt to upgrade to f-strings
1 parent 7a68e2f commit 9a19a98

File tree

9 files changed

+18
-28
lines changed

9 files changed

+18
-28
lines changed

elasticsearch_dsl/analysis.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class AnalysisBase:
2626
def _type_shortcut(cls, name_or_instance, type=None, **kwargs):
2727
if isinstance(name_or_instance, cls):
2828
if type or kwargs:
29-
raise ValueError("%s() cannot accept parameters." % cls.__name__)
29+
raise ValueError(f"{cls.__name__}() cannot accept parameters.")
3030
return name_or_instance
3131

3232
if not (type or kwargs):

elasticsearch_dsl/connections.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def remove_connection(self, alias):
7272
errors += 1
7373

7474
if errors == 2:
75-
raise KeyError("There is no connection with alias %r." % alias)
75+
raise KeyError(f"There is no connection with alias {alias!r}.")
7676

7777
def create_connection(self, alias="default", **kwargs):
7878
"""
@@ -108,7 +108,7 @@ def get_connection(self, alias="default"):
108108
return self.create_connection(alias, **self._kwargs[alias])
109109
except KeyError:
110110
# no connection and no kwargs to set one up
111-
raise KeyError("There is no connection with alias %r." % alias)
111+
raise KeyError(f"There is no connection with alias {alias!r}.")
112112

113113

114114
connections = Connections()

elasticsearch_dsl/document.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ def mget(
275275
raise RequestError(400, message, error_docs)
276276
if missing_docs:
277277
missing_ids = [doc["_id"] for doc in missing_docs]
278-
message = "Documents %s not found." % ", ".join(missing_ids)
278+
message = f"Documents {', '.join(missing_ids)} not found."
279279
raise NotFoundError(404, message, {"docs": missing_docs})
280280
return objs
281281

elasticsearch_dsl/field.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ def _deserialize(self, data):
265265
data = parser.parse(data)
266266
except Exception as e:
267267
raise ValidationException(
268-
"Could not parse date from the value (%r)" % data, e
268+
f"Could not parse date from the value ({data!r})", e
269269
)
270270

271271
if isinstance(data, datetime):
@@ -278,7 +278,7 @@ def _deserialize(self, data):
278278
# Divide by a float to preserve milliseconds on the datetime.
279279
return datetime.utcfromtimestamp(data / 1000.0)
280280

281-
raise ValidationException("Could not parse date from the value (%r)" % data)
281+
raise ValidationException(f"Could not parse date from the value ({data!r})")
282282

283283

284284
class Text(Field):

elasticsearch_dsl/function.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def SF(name_or_sf, **params):
3838
elif len(sf) == 1:
3939
name, params = sf.popitem()
4040
else:
41-
raise ValueError("SF() got an unexpected fields in the dictionary: %r" % sf)
41+
raise ValueError(f"SF() got an unexpected fields in the dictionary: {sf!r}")
4242

4343
# boost factor special case, see elasticsearch #6343
4444
if not isinstance(params, collections.abc.Mapping):

elasticsearch_dsl/search.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class ProxyDescriptor:
8686
"""
8787

8888
def __init__(self, name):
89-
self._attr_name = "_%s_proxy" % name
89+
self._attr_name = f"_{name}_proxy"
9090

9191
def __get__(self, instance, owner):
9292
return getattr(instance, self._attr_name)

elasticsearch_dsl/utils.py

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -151,19 +151,15 @@ def __getattr__(self, attr_name):
151151
return self.__getitem__(attr_name)
152152
except KeyError:
153153
raise AttributeError(
154-
"{!r} object has no attribute {!r}".format(
155-
self.__class__.__name__, attr_name
156-
)
154+
f"{self.__class__.__name__!r} object has no attribute {attr_name!r}"
157155
)
158156

159157
def __delattr__(self, attr_name):
160158
try:
161159
del self._d_[attr_name]
162160
except KeyError:
163161
raise AttributeError(
164-
"{!r} object has no attribute {!r}".format(
165-
self.__class__.__name__, attr_name
166-
)
162+
f"{self.__class__.__name__!r} object has no attribute {attr_name!r}"
167163
)
168164

169165
def __getitem__(self, key):
@@ -224,7 +220,7 @@ def get_dsl_type(cls, name):
224220
try:
225221
return cls._types[name]
226222
except KeyError:
227-
raise UnknownDslObject("DSL type %s does not exist." % name)
223+
raise UnknownDslObject(f"DSL type {name} does not exist.")
228224

229225

230226
class DslBase(metaclass=DslMeta):
@@ -266,7 +262,7 @@ def __init__(self, _expand__to_dot=EXPAND__TO_DOT, **params):
266262
def _repr_params(self):
267263
"""Produce a repr of all our parameters to be used in __repr__."""
268264
return ", ".join(
269-
"{}={!r}".format(n.replace(".", "__"), v)
265+
f"{n.replace('.', '__')}={v!r}"
270266
for (n, v) in sorted(self._params.items())
271267
# make sure we don't include empty typed params
272268
if "type" not in self._param_defs.get(n, {}) or v
@@ -319,9 +315,7 @@ def _setattr(self, name, value):
319315
def __getattr__(self, name):
320316
if name.startswith("_"):
321317
raise AttributeError(
322-
"{!r} object has no attribute {!r}".format(
323-
self.__class__.__name__, name
324-
)
318+
f"{self.__class__.__name__!r} object has no attribute {name!r}"
325319
)
326320

327321
value = None
@@ -338,9 +332,7 @@ def __getattr__(self, name):
338332
value = self._params.setdefault(name, {})
339333
if value is None:
340334
raise AttributeError(
341-
"{!r} object has no attribute {!r}".format(
342-
self.__class__.__name__, name
343-
)
335+
f"{self.__class__.__name__!r} object has no attribute {name!r}"
344336
)
345337

346338
# wrap nested dicts in AttrDict for convenient access
@@ -541,9 +533,7 @@ def merge(data, new_data, raise_on_conflict=False):
541533
and isinstance(new_data, (AttrDict, collections.abc.Mapping))
542534
):
543535
raise ValueError(
544-
"You can only merge two dicts! Got {!r} and {!r} instead.".format(
545-
data, new_data
546-
)
536+
f"You can only merge two dicts! Got {data!r} and {new_data!r} instead."
547537
)
548538

549539
for key, value in new_data.items():
@@ -554,7 +544,7 @@ def merge(data, new_data, raise_on_conflict=False):
554544
):
555545
merge(data[key], value, raise_on_conflict)
556546
elif key in data and data[key] != value and raise_on_conflict:
557-
raise ValueError("Incompatible data for key %r, cannot be merged." % key)
547+
raise ValueError(f"Incompatible data for key {key!r}, cannot be merged.")
558548
else:
559549
data[key] = value
560550

elasticsearch_dsl/wrappers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def __init__(self, *args, **kwargs):
3939

4040
for k in data:
4141
if k not in self.OPS:
42-
raise ValueError("Range received an unknown operator %r" % k)
42+
raise ValueError(f"Range received an unknown operator {k!r}")
4343

4444
if "gt" in data and "gte" in data:
4545
raise ValueError("You cannot specify both gt and gte for Range.")

tests/test_result.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def test_interactive_helpers(dummy_response):
8989
)
9090

9191
assert res
92-
assert "<Response: %s>" % rhits == repr(res)
92+
assert f"<Response: {rhits}>" == repr(res)
9393
assert rhits == repr(hits)
9494
assert {"meta", "city", "name"} == set(dir(h))
9595
assert "<Hit(test-index/elasticsearch): %r>" % dummy_response["hits"]["hits"][0][

0 commit comments

Comments
 (0)