Skip to content

Commit cdec6d1

Browse files
committed
Adds pyupgrade in pre-commit
1 parent 47b638a commit cdec6d1

File tree

5 files changed

+45
-45
lines changed

5 files changed

+45
-45
lines changed

.pre-commit-config.yaml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,15 @@ repos:
88
- id: end-of-file-fixer
99
- id: check-yaml
1010
- id: check-added-large-files
11-
- repo: https://github.com/psf/black
12-
rev: 22.3.0
13-
hooks:
14-
- id: black
1511
- repo: https://gitlab.com/pycqa/flake8
1612
rev: 4.0.1
1713
hooks:
1814
- id: flake8
15+
- repo: https://github.com/asottile/pyupgrade
16+
rev: v2.32.1
17+
hooks:
18+
- id: pyupgrade
19+
- repo: https://github.com/psf/black
20+
rev: 22.3.0
21+
hooks:
22+
- id: black

fortls/__init__.py

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -86,18 +86,18 @@ def debug_server_general(args, settings):
8686
"Specified 'debug_rootpath' does not exist or is not a directory"
8787
)
8888
print('\nTesting "initialize" request:')
89-
print(' Root = "{0}"'.format(args.debug_rootpath))
89+
print(' Root = "{}"'.format(args.debug_rootpath))
9090
s.serve_initialize({"params": {"rootPath": args.debug_rootpath}})
9191
if len(s.post_messages) == 0:
9292
print(" Successful!")
9393
else:
9494
print(" Successful with errors:")
9595
for message in s.post_messages:
96-
print(" {0}".format(message[1]))
96+
print(" {}".format(message[1]))
9797
# Print module directories
9898
print("\n Source directories:")
9999
for source_dir in s.source_dirs:
100-
print(" {0}".format(source_dir))
100+
print(" {}".format(source_dir))
101101
#
102102
if args.debug_diagnostics:
103103
print('\nTesting "textDocument/publishDiagnostics" notification:')
@@ -117,7 +117,7 @@ def debug_server_general(args, settings):
117117
sline = diag["range"]["start"]["line"]
118118
message = diag["message"]
119119
sev = sev_map[diag["severity"] - 1]
120-
print(' {0:5d}:{1} "{2}"'.format(sline, sev, message))
120+
print(' {:5d}:{} "{}"'.format(sline, sev, message))
121121
#
122122
if args.debug_symbols:
123123
print('\nTesting "textDocument/documentSymbol" request:')
@@ -192,7 +192,7 @@ def debug_server_general(args, settings):
192192
else:
193193
for obj in completion_results:
194194
print(
195-
" {0}: {1} -> {2}".format(
195+
" {}: {} -> {}".format(
196196
obj["kind"], obj["label"], obj["detail"]
197197
)
198198
)
@@ -220,11 +220,11 @@ def debug_server_general(args, settings):
220220
print(json.dumps(signature_results, indent=2))
221221
else:
222222
active_param = signature_results.get("activeParameter", 0)
223-
print(" Active param = {0}".format(active_param))
223+
print(" Active param = {}".format(active_param))
224224
active_signature = signature_results.get("activeSignature", 0)
225-
print(" Active sig = {0}".format(active_signature))
225+
print(" Active sig = {}".format(active_signature))
226226
for i, signature in enumerate(signature_results["signatures"]):
227-
print(" {0}".format(signature["label"]))
227+
print(" {}".format(signature["label"]))
228228
for j, obj in enumerate(signature["parameters"]):
229229
if (i == active_signature) and (j == active_param):
230230
active_mark = "*"
@@ -278,14 +278,14 @@ def debug_server_general(args, settings):
278278
if args.debug_full_result:
279279
print(json.dumps(definition_results, indent=2))
280280
else:
281-
print(' URI = "{0}"'.format(definition_results["uri"]))
281+
print(' URI = "{}"'.format(definition_results["uri"]))
282282
print(
283-
" Line = {0}".format(
283+
" Line = {}".format(
284284
definition_results["range"]["start"]["line"] + 1
285285
)
286286
)
287287
print(
288-
" Char = {0}".format(
288+
" Char = {}".format(
289289
definition_results["range"]["start"]["character"] + 1
290290
)
291291
)
@@ -345,7 +345,7 @@ def debug_server_general(args, settings):
345345
print("=======")
346346
for result in ref_results:
347347
print(
348-
" {0} ({1}, {2})".format(
348+
" {} ({}, {})".format(
349349
result["uri"],
350350
result["range"]["start"]["line"] + 1,
351351
result["range"]["start"]["character"] + 1,
@@ -379,7 +379,7 @@ def debug_server_general(args, settings):
379379
print("=======")
380380
for uri, result in ref_results["changes"].items():
381381
path = path_from_uri(uri)
382-
print('File: "{0}"'.format(path))
382+
print('File: "{}"'.format(path))
383383
file_obj = s.workspace.get(path)
384384
if file_obj is not None:
385385
file_contents = file_obj.contents_split
@@ -388,22 +388,22 @@ def debug_server_general(args, settings):
388388
end_line = change["range"]["end"]["line"]
389389
start_col = change["range"]["start"]["character"]
390390
end_col = change["range"]["end"]["character"]
391-
print(" {0}, {1}".format(start_line + 1, end_line + 1))
391+
print(" {}, {}".format(start_line + 1, end_line + 1))
392392
new_contents = []
393393
for i in range(start_line, end_line + 1):
394394
line = file_contents[i]
395-
print(" - {0}".format(line))
395+
print(" - {}".format(line))
396396
if i == start_line:
397397
new_contents.append(
398398
line[:start_col] + change["newText"]
399399
)
400400
if i == end_line:
401401
new_contents[-1] += line[end_col:]
402402
for line in new_contents:
403-
print(" + {0}".format(line))
403+
print(" + {}".format(line))
404404
print()
405405
else:
406-
print('Unknown file: "{0}"'.format(path))
406+
print('Unknown file: "{}"'.format(path))
407407
print("=======")
408408
#
409409
if args.debug_actions:
@@ -434,12 +434,10 @@ def debug_server_general(args, settings):
434434
else:
435435
for result in action_results:
436436
print(
437-
"Kind = '{0}', Title = '{1}'".format(
438-
result["kind"], result["title"]
439-
)
437+
"Kind = '{}', Title = '{}'".format(result["kind"], result["title"])
440438
)
441439
for editUri, editChange in result["edit"]["changes"].items():
442-
print("\nChange: URI = '{0}'".format(editUri))
440+
print("\nChange: URI = '{}'".format(editUri))
443441
pp.pprint(editChange)
444442
print()
445443
tmpout.close()
@@ -485,7 +483,7 @@ def debug_server_parser(args):
485483
print(f"Error while parsing '{args.config}' settings file")
486484
#
487485
print("\nTesting parser")
488-
print(' File = "{0}"'.format(args.debug_filepath))
486+
print(' File = "{}"'.format(args.debug_filepath))
489487
file_obj = fortran_file(args.debug_filepath, pp_suffixes)
490488
err_str, _ = file_obj.load_from_disk()
491489
if err_str:
@@ -495,11 +493,11 @@ def debug_server_parser(args):
495493
file_ast = file_obj.parse(debug=True, pp_defs=pp_defs, include_dirs=include_dirs)
496494
print("\n=========\nObject Tree\n=========\n")
497495
for obj in file_ast.get_scopes():
498-
print("{0}: {1}".format(obj.get_type(), obj.FQSN))
496+
print("{}: {}".format(obj.get_type(), obj.FQSN))
499497
print_children(obj)
500498
print("\n=========\nExportable Objects\n=========\n")
501499
for _, obj in file_ast.global_dict.items():
502-
print("{0}: {1}".format(obj.get_type(), obj.FQSN))
500+
print("{}: {}".format(obj.get_type(), obj.FQSN))
503501

504502

505503
def check_request_params(args, loc_needed=True):
@@ -508,17 +506,17 @@ def check_request_params(args, loc_needed=True):
508506
file_exists = os.path.isfile(args.debug_filepath)
509507
if file_exists is False:
510508
error_exit("Specified 'debug_filepath' does not exist")
511-
print(' File = "{0}"'.format(args.debug_filepath))
509+
print(' File = "{}"'.format(args.debug_filepath))
512510
if loc_needed:
513511
if args.debug_line is None:
514512
error_exit("'debug_line' not specified for debug request")
515-
print(" Line = {0}".format(args.debug_line))
513+
print(" Line = {}".format(args.debug_line))
516514
if args.debug_char is None:
517515
error_exit("'debug_char' not specified for debug request")
518-
print(" Char = {0}\n".format(args.debug_char))
516+
print(" Char = {}\n".format(args.debug_char))
519517

520518

521519
def print_children(obj, indent=""):
522520
for child in obj.get_children():
523-
print(" {0}{1}: {2}".format(indent, child.get_type(), child.FQSN))
521+
print(" {}{}: {}".format(indent, child.get_type(), child.FQSN))
524522
print_children(child, indent + " ")

fortls/helper_functions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,10 @@ def strip_strings(in_line: str, maintain_len: bool = False) -> str:
107107
"""
108108

109109
def repl_sq(m):
110-
return "'{0}'".format(" " * (len(m.group()) - 2))
110+
return "'{}'".format(" " * (len(m.group()) - 2))
111111

112112
def repl_dq(m):
113-
return '"{0}"'.format(" " * (len(m.group()) - 2))
113+
return '"{}"'.format(" " * (len(m.group()) - 2))
114114

115115
if maintain_len:
116116
out_line = FRegex.SQ_STRING.sub(repl_sq, in_line)

fortls/objects.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1666,7 +1666,7 @@ def get_hover(self, long=False, include_doc=True, drop_arg=-1):
16661666
if self.is_parameter() and self.param_val:
16671667
hover_str += f" :: {self.name} = {self.param_val}"
16681668
if include_doc and (doc_str is not None):
1669-
hover_str += "\n {0}".format("\n ".join(doc_str.splitlines()))
1669+
hover_str += "\n {}".format("\n ".join(doc_str.splitlines()))
16701670
return hover_str, True
16711671

16721672
def get_keywords(self):

test/test_interface.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ def test_command_line_file_parsing_options():
2828
"--source_dirs tmp ./local /usr/include/** --incl_suffixes .FF .fpc .h f20"
2929
" --excl_suffixes _tmp.f90 _h5hut_tests.F90 --excl_paths exclude tests".split()
3030
)
31-
assert args.source_dirs == set(["tmp", "./local", "/usr/include/**"])
31+
assert args.source_dirs == {"tmp", "./local", "/usr/include/**"}
3232
assert args.incl_suffixes == [".FF", ".fpc", ".h", "f20"]
33-
assert args.excl_suffixes == set(["_tmp.f90", "_h5hut_tests.F90"])
34-
assert args.excl_paths == set(["exclude", "tests"])
33+
assert args.excl_suffixes == {"_tmp.f90", "_h5hut_tests.F90"}
34+
assert args.excl_paths == {"exclude", "tests"}
3535

3636

3737
def test_command_line_autocomplete_options():
@@ -69,7 +69,7 @@ def test_command_line_preprocessor_options():
6969
' {"HAVE_PETSC":"","HAVE_ZOLTAN":"","Mat":"type(tMat)"}'.split()
7070
)
7171
assert args.pp_suffixes == [".h", ".fh"]
72-
assert args.include_dirs == set(["/usr/include/**", "./local/incl"])
72+
assert args.include_dirs == {"/usr/include/**", "./local/incl"}
7373
assert args.pp_defs == {"HAVE_PETSC": "", "HAVE_ZOLTAN": "", "Mat": "type(tMat)"}
7474

7575

@@ -109,12 +109,10 @@ def test_config_file_general_options():
109109
def test_config_file_dir_parsing_options():
110110
server, r = unittest_server_init()
111111
# File parsing
112-
assert server.source_dirs == set(
113-
[f'{r/"subdir"}', f'{r/"pp"}', f'{r/"pp"/"include"}']
114-
)
112+
assert server.source_dirs == {f'{r/"subdir"}', f'{r/"pp"}', f'{r/"pp"/"include"}'}
115113
assert server.incl_suffixes == [".FF", ".fpc", ".h", "f20"]
116-
assert server.excl_suffixes == set(["_tmp.f90", "_h5hut_tests.F90"])
117-
assert server.excl_paths == set([f'{r/"excldir"}', f'{r/"hover"}'])
114+
assert server.excl_suffixes == {"_tmp.f90", "_h5hut_tests.F90"}
115+
assert server.excl_paths == {f'{r/"excldir"}', f'{r/"hover"}'}
118116

119117

120118
def test_config_file_autocomplete_options():
@@ -146,7 +144,7 @@ def test_config_file_preprocessor_options():
146144
server, root = unittest_server_init()
147145
# Preprocessor options
148146
assert server.pp_suffixes == [".h", ".fh"]
149-
assert server.include_dirs == set([f'{root/"include"}'])
147+
assert server.include_dirs == {f'{root/"include"}'}
150148
assert server.pp_defs == {
151149
"HAVE_PETSC": "",
152150
"HAVE_ZOLTAN": "",

0 commit comments

Comments
 (0)