Skip to content

Commit 10d8abf

Browse files
committed
Fix nested calls with commas in yapf hook.
1 parent 0d6a348 commit 10d8abf

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

formate/__init__.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,14 @@ def yapf_hook(source: str, formate_global_config: Optional[Mapping] = None, **kw
224224
config.write(fp)
225225

226226
tree = ParseCodeToTree(source)
227-
return FormatTree(tree, style_config=str(config_file))
227+
reformatted_code: str = FormatTree(tree, style_config=str(config_file))
228+
229+
# Yapf can collapse nested calls onto one line but does nothing about the commas.
230+
bad_nested_call = "), )"
231+
while bad_nested_call in reformatted_code:
232+
reformatted_code = reformatted_code.replace(bad_nested_call, "))")
233+
234+
return reformatted_code
228235

229236

230237
class Reformatter:

formate/classes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ def _normalise_name(name: str) -> str:
8282

8383
return _normalize_pattern.sub('-', name).lower()
8484

85+
8586
@pretty_repr
8687
@serde
8788
@attrs.define

0 commit comments

Comments
 (0)