Skip to content

Commit 36fa346

Browse files
ruff format
1 parent d142a75 commit 36fa346

File tree

2 files changed

+30
-23
lines changed

2 files changed

+30
-23
lines changed

edtf/parser/grammar.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ def f(toks):
344344
)
345345

346346

347-
@remapparams(parseAll='parse_all')
347+
@remapparams(parseAll="parse_all")
348348
def parse_edtf(
349349
input_string: str,
350350
parse_all: bool = True,

edtf/util.py

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
11
#!/usr/bin/env python3
22

3-
'''
3+
"""
44
Assorted utility functions.
5-
'''
5+
"""
66

77
from functools import update_wrapper
88
from logging import warning
99
from traceback import extract_stack
1010

1111

1212
def remapparams(**remap):
13-
'''
13+
"""
1414
Remap the specified named parameters.
1515
1616
Example to support an obsolete `parseAll` parameter:
1717
1818
@remapparams(parseAll='parse_all')
1919
def parse(s, parse_all=True):
2020
21-
'''
21+
"""
2222
if not remap:
23-
raise ValueError('no parameters specified for remapping')
23+
raise ValueError("no parameters specified for remapping")
2424
for old, new in remap.items():
2525
if new in remap:
26-
raise ValueError(f'{old}={new!r}: {new!r} is also remapped')
26+
raise ValueError(f"{old}={new!r}: {new!r} is also remapped")
2727

2828
def remapparams_decorator(func):
29-
'''The decorator to apply the remappings.'''
29+
"""The decorator to apply the remappings."""
3030
# a record of callers whose parameters were remapped
3131
remapped_callers = set()
3232

@@ -38,7 +38,9 @@ def remapparams_wrapper(*a, **kw):
3838
except KeyError:
3939
continue
4040
if remapped in kw:
41-
raise ValueError(f'remap {param}= to {remapped}=: this is already present in the keyword arguments')
41+
raise ValueError(
42+
f"remap {param}= to {remapped}=: this is already present in the keyword arguments"
43+
)
4244
del kw[param]
4345
kw[remapped] = value
4446
remappings[param] = remapped
@@ -48,9 +50,13 @@ def remapparams_wrapper(*a, **kw):
4850
if caller_key not in remapped_callers:
4951
warning(
5052
"call of %s.%s() from %s:%d: remapped the following obsolete parameters: %s",
51-
func.__module__, func.__name__,
52-
caller_frame.filename, caller_frame.lineno,
53-
", ".join(sorted(f'{old}->{new}' for old, new in remappings.items())),
53+
func.__module__,
54+
func.__name__,
55+
caller_frame.filename,
56+
caller_frame.lineno,
57+
", ".join(
58+
sorted(f"{old}->{new}" for old, new in remappings.items())
59+
),
5460
)
5561
remapped_callers.add(caller_key)
5662
return func(*a, **kw)
@@ -60,29 +66,29 @@ def remapparams_wrapper(*a, **kw):
6066

6167
return remapparams_decorator
6268

63-
if __name__ == '__main__':
6469

65-
@remapparams(parseAll='parse_all')
70+
if __name__ == "__main__":
71+
72+
@remapparams(parseAll="parse_all")
6673
def parser(s, parse_all=True):
6774
pass
6875

69-
assert parser.__name__ == 'parser' # noqa: S101
70-
parser('foo')
76+
assert parser.__name__ == "parser" # noqa: S101
77+
parser("foo")
7178
# this should not warn
72-
parser('foo', parse_all=False)
79+
parser("foo", parse_all=False)
7380
# this should warn, but only once
7481
for _ in 1, 2:
75-
parser('foo', parseAll=False)
82+
parser("foo", parseAll=False)
7683
try:
77-
parser('foo', parseAll=False, parse_all=True)
84+
parser("foo", parseAll=False, parse_all=True)
7885
except ValueError:
7986
pass
8087
else:
81-
raise AssertionError(
82-
"expected ValueError because of duplicated parameters"
83-
)
88+
raise AssertionError("expected ValueError because of duplicated parameters")
8489

8590
try:
91+
8692
@remapparams()
8793
def no_remappings():
8894
pass
@@ -93,7 +99,8 @@ def no_remappings():
9399
"expected ValueError from @remapparams() because no remappings"
94100
)
95101
try:
96-
@remapparams(p1='p2', p2='p3')
102+
103+
@remapparams(p1="p2", p2="p3")
97104
def no_remappings():
98105
pass
99106
except ValueError:

0 commit comments

Comments
 (0)