Skip to content

Commit 9a3694d

Browse files
authored
chore: %-formatting to f-string
* chore: %-formatting to f-string pylint-dev/pylint#1788 (comment) --- Jakub I didn't agree with using f-strings in logging calls because I don't think log messages need to be super simple to read. If in the future you find out it was stupid idea, then remember that it was a Jakub's stupid decision. ---- Closes #144
1 parent e78a34c commit 9a3694d

File tree

7 files changed

+185
-185
lines changed

7 files changed

+185
-185
lines changed

pyodata/client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ def _fetch_metadata(connection, url, logger):
1919

2020
if resp.status_code != 200:
2121
raise HttpError(
22-
'Metadata request failed, status code: {}, body:\n{}'.format(resp.status_code, resp.content), resp)
22+
f'Metadata request failed, status code: {resp.status_code}, body:\n{resp.content}', resp)
2323

2424
mime_type = resp.headers['content-type']
2525
if not any((typ in ['application/xml', 'text/xml'] for typ in mime_type.split(';'))):
2626
raise HttpError(
27-
'Metadata request did not return XML, MIME type: {}, body:\n{}'.format(mime_type, resp.content),
27+
f'Metadata request did not return XML, MIME type: {mime_type}, body:\n{resp.content}',
2828
resp)
2929

3030
return resp.content
@@ -73,4 +73,4 @@ def __new__(cls, url, connection, odata_version=ODATA_VERSION_2, namespaces=None
7373

7474
return service
7575

76-
raise PyODataException('No implementation for selected odata version {}'.format(odata_version))
76+
raise PyODataException(f'No implementation for selected odata version {odata_version}')

pyodata/v2/model.py

Lines changed: 78 additions & 78 deletions
Large diffs are not rendered by default.

pyodata/v2/service.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,15 @@ def encode_multipart(boundary, http_requests):
4545

4646
for req in http_requests:
4747

48-
lines.append('--{0}'.format(boundary))
48+
lines.append(f'--{boundary}')
4949

5050
if not isinstance(req, MultipartRequest):
5151
lines.extend(('Content-Type: application/http ', 'Content-Transfer-Encoding:binary'))
5252

5353
lines.append('')
5454

5555
# request line (method + path + query params)
56-
line = '{method} {path}'.format(method=req.get_method(), path=req.get_path())
56+
line = f'{req.get_method()} {req.get_path()}'
5757
query_params = '&'.join(['{}={}'.format(key, val) for key, val in req.get_query_params().items()])
5858
if query_params:
5959
line += '?' + query_params
@@ -63,7 +63,7 @@ def encode_multipart(boundary, http_requests):
6363

6464
# request specific headers
6565
for hdr, hdr_val in req.get_headers().items():
66-
lines.append('{}: {}'.format(hdr, hdr_val))
66+
lines.append(f'{hdr}: {hdr_val}')
6767

6868
lines.append('')
6969

@@ -76,7 +76,7 @@ def encode_multipart(boundary, http_requests):
7676
# 400 Bad fromat from SAP gateway
7777
lines.append('')
7878

79-
lines.append('--{0}--'.format(boundary))
79+
lines.append(f'--{boundary}--')
8080

8181
return '\r\n'.join(lines)
8282

@@ -96,7 +96,7 @@ def decode(message):
9696
messages.append(part.get_payload())
9797
return messages
9898

99-
data = "Content-Type: {}\n".format(content_type) + data
99+
data = f"Content-Type: {content_type}\n" + data
100100
parser = Parser()
101101
parsed = parser.parsestr(data)
102102
decoded = decode(parsed)
@@ -196,7 +196,7 @@ def __init__(self, entity_type, single_key=None, **args):
196196
else:
197197
for key_prop in self._key:
198198
if key_prop.name not in args:
199-
raise PyODataException('Missing value for key property {}'.format(key_prop.name))
199+
raise PyODataException(f'Missing value for key property {key_prop.name}')
200200

201201
self._type = EntityKey.TYPE_COMPLEX
202202

@@ -220,14 +220,14 @@ def to_key_string_without_parentheses(self):
220220
# raise RuntimeError('Entity key is not complete, missing value of property: {0}'.format(key_prop.name))
221221

222222
key_pairs.append(
223-
'{0}={1}'.format(key_prop.name, key_prop.to_literal(self._proprties[key_prop.name])))
223+
f'{key_prop.name}={key_prop.to_literal(self._proprties[key_prop.name])}')
224224

225225
return ','.join(key_pairs)
226226

227227
def to_key_string(self):
228228
"""Gets the string representation of the key, including parentheses"""
229229

230-
return '({})'.format(self.to_key_string_without_parentheses())
230+
return f'({self.to_key_string_without_parentheses()})'
231231

232232
def __repr__(self):
233233
return self.to_key_string()
@@ -292,7 +292,7 @@ def add_headers(self, value):
292292
"""
293293

294294
if not isinstance(value, dict):
295-
raise TypeError("Headers must be of type 'dict' not {}".format(type(value)))
295+
raise TypeError(f"Headers must be of type 'dict' not {type(value)}")
296296

297297
self._headers.update(value)
298298

@@ -420,7 +420,7 @@ def __init__(self, handler, master_key, entity_set_proxy, nav_property):
420420
self._nav_property = nav_property
421421

422422
def get_path(self):
423-
return "{}/{}".format(super(NavEntityGetRequest, self).get_path(), self._nav_property)
423+
return f"{super(NavEntityGetRequest, self).get_path()}/{self._nav_property}"
424424

425425

426426
class EntityCreateRequest(ODataHttpRequest):
@@ -586,7 +586,7 @@ def set(self, **kwargs):
586586
val = self._entity_type.proprty(key).to_json(val)
587587
except KeyError:
588588
raise PyODataException(
589-
'Property {} is not declared in {} entity type'.format(key, self._entity_type.name))
589+
f'Property {key} is not declared in {self._entity_type.name} entity type')
590590

591591
self._values[key] = val
592592

@@ -858,7 +858,7 @@ def nav(self, nav_property):
858858
navigation_entity_set = self._service.schema.entity_set(end.entity_set_name, association_info.namespace)
859859

860860
if not navigation_entity_set:
861-
raise PyODataException('No association set for role {}'.format(navigation_property.to_role))
861+
raise PyODataException(f'No association set for role {navigation_property.to_role}')
862862

863863
roles = navigation_property.association.end_roles
864864
if all((role.multiplicity != model.EndRole.MULTIPLICITY_ZERO_OR_MORE for role in roles)):
@@ -974,7 +974,7 @@ def build_expression(operator, operands):
974974
if len(operands) < 2:
975975
raise ExpressionError('The $filter operator \'{}\' needs at least two operands'.format(operator))
976976

977-
return '({})'.format(' {} '.format(operator).join(operands))
977+
return f"({' {} '.format(operator).join(operands)})"
978978

979979
@staticmethod
980980
def and_(*operands):
@@ -992,7 +992,7 @@ def or_(*operands):
992992
def format_filter(proprty, operator, value):
993993
"""Creates a filter expression """
994994

995-
return '{} {} {}'.format(proprty.name, operator, proprty.to_literal(value))
995+
return f'{proprty.name} {operator} {proprty.to_literal(value)}'
996996

997997
def __eq__(self, value):
998998
return GetEntitySetFilter.format_filter(self._proprty, 'eq', value)
@@ -1194,7 +1194,7 @@ def _build_expression(self, field_name, operator, value):
11941194

11951195
if operator == 'range':
11961196
if not isinstance(value, (tuple, list)):
1197-
raise TypeError('Range must be tuple or list not {}'.format(type(value)))
1197+
raise TypeError(f'Range must be tuple or list not {type(value)}')
11981198

11991199
if len(value) != 2:
12001200
raise ValueError('Only two items can be passed in a range.')
@@ -1321,7 +1321,7 @@ def nav(self, nav_property, key):
13211321

13221322
if not navigation_entity_set:
13231323
raise PyODataException(
1324-
'No association set for role {} {}'.format(navigation_property.to_role, association_set.end_roles))
1324+
f'No association set for role {navigation_property.to_role} {association_set.end_roles}')
13251325

13261326
roles = navigation_property.association.end_roles
13271327
if all((role.multiplicity != model.EndRole.MULTIPLICITY_ZERO_OR_MORE for role in roles)):
@@ -1498,7 +1498,7 @@ def __getattr__(self, name):
14981498
return self._entity_sets[name]
14991499
except KeyError:
15001500
raise AttributeError(
1501-
'EntitySet {0} not defined in {1}.'.format(name, ','.join(list(self._entity_sets.keys()))))
1501+
f"EntitySet {name} not defined in {','.join(list(self._entity_sets.keys()))}.")
15021502

15031503

15041504
class FunctionContainer:
@@ -1519,7 +1519,7 @@ def __getattr__(self, name):
15191519

15201520
if name not in self._functions:
15211521
raise AttributeError(
1522-
'Function {0} not defined in {1}.'.format(name, ','.join(list(self._functions.keys()))))
1522+
f"Function {name} not defined in {','.join(list(self._functions.keys()))}.")
15231523

15241524
fimport = self._service.schema.function_import(name)
15251525

@@ -1742,7 +1742,7 @@ def get_boundary(self):
17421742

17431743
def get_default_headers(self):
17441744
# pylint: disable=no-self-use
1745-
return {'Content-Type': 'multipart/mixed;boundary={}'.format(self.get_boundary())}
1745+
return {'Content-Type': f'multipart/mixed;boundary={self.get_boundary()}'}
17461746

17471747
def get_body(self):
17481748
return encode_multipart(self.get_boundary(), self.requests)

pyodata/vendor/SAP.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def json_get(obj, member, typ, default=None):
1919

2020
value = obj.get(member, default)
2121
if not isinstance(value, typ):
22-
raise ValueError('%s is not a %s' % (member, typ.__name__))
22+
raise ValueError(f'{member} is not a {typ.__name__}')
2323

2424
return value
2525

tests/test_client.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def test_create_service_application_xml(metadata):
4040

4141
responses.add(
4242
responses.GET,
43-
"{0}/$metadata".format(SERVICE_URL),
43+
f"{SERVICE_URL}/$metadata",
4444
content_type='application/xml',
4545
body=metadata,
4646
status=200)
@@ -62,7 +62,7 @@ def test_create_service_text_xml(metadata):
6262

6363
responses.add(
6464
responses.GET,
65-
"{0}/$metadata".format(SERVICE_URL),
65+
f"{SERVICE_URL}/$metadata",
6666
content_type='text/xml',
6767
body=metadata,
6868
status=200)
@@ -84,7 +84,7 @@ def test_metadata_not_reachable():
8484

8585
responses.add(
8686
responses.GET,
87-
"{0}/$metadata".format(SERVICE_URL),
87+
f"{SERVICE_URL}/$metadata",
8888
content_type='text/html',
8989
status=404)
9090

@@ -99,7 +99,7 @@ def test_metadata_saml_not_authorized():
9999

100100
responses.add(
101101
responses.GET,
102-
"{0}/$metadata".format(SERVICE_URL),
102+
f"{SERVICE_URL}/$metadata",
103103
content_type='text/html; charset=utf-8',
104104
status=200)
105105

@@ -116,7 +116,7 @@ def test_client_custom_configuration(mock_warning, metadata):
116116

117117
responses.add(
118118
responses.GET,
119-
"{0}/$metadata".format(SERVICE_URL),
119+
f"{SERVICE_URL}/$metadata",
120120
content_type='application/xml',
121121
body=metadata,
122122
status=200)

0 commit comments

Comments
 (0)