Don't reorder parameters in function calls#7268
Conversation
|
|
||
| group(&format_inner).fmt(f) | ||
| }), | ||
| &format_with(|f| format_function_header(f, item)), |
There was a problem hiding this comment.
This isn't really part of the PR but i got confused so i split this into it's own function (no functional changes). It's a separate commit already i can easily split the branch if you want
There was a problem hiding this comment.
I think I would prefer if you write it as (I'm somewhat certain that this should work):
fn format_function_header(item: &StmtFunctionDef) -> impl Format<PyFormatContext<'_>> {
format_with(move |f| {
...
})
}It avoids the nested function call.
There was a problem hiding this comment.
i prefer the flatter function body
MichaReiser
left a comment
There was a problem hiding this comment.
Can you add the similarity index comparison between the baseline and this PR?
|
|
||
| group(&format_inner).fmt(f) | ||
| }), | ||
| &format_with(|f| format_function_header(f, item)), |
There was a problem hiding this comment.
I think I would prefer if you write it as (I'm somewhat certain that this should work):
fn format_function_header(item: &StmtFunctionDef) -> impl Format<PyFormatContext<'_>> {
format_with(move |f| {
...
})
}It avoids the nested function call.
8b4a36a to
78867ef
Compare
|
Current dependencies on/for this PR:
This comment was auto-generated by Graphite. |
78867ef to
f6e0492
Compare
PR Check ResultsEcosystem✅ ecosystem check detected no changes. |
f394565 to
492cd7a
Compare
454aa03 to
f4037d9
Compare
492cd7a to
d374956
Compare
| *args, # d | ||
| # c |
There was a problem hiding this comment.
these get switched but that seems fine to me
## Motivation
The `ast::Arguments` for call argument are split into positional
arguments (args) and keywords arguments (keywords). We currently assume
that call consists of first args and then keywords, which is generally
the case, but not always:
```python
f(*args, a=2, *args2, **kwargs)
class A(*args, a=2, *args2, **kwargs):
pass
```
The consequence is accidentally reordering arguments
(#7268).
## Summary
`Arguments::args_and_keywords` returns an iterator of an `ArgOrKeyword`
enum that yields args and keywords in the correct order. I've fixed the
obvious `args` and `keywords` usages, but there might be some cases with
wrong assumptions remaining.
## Test Plan
The generator got new test cases, otherwise the stacked PR
(#7268) which uncovered this.
d374956 to
b30e268
Compare

Summary
In
f(*args, a=b, *args2, **kwargs)the args (*args,*args2) and keywords (a=b,**kwargs) are interleaved, which we previously didn't handle.Fixes #6498
main
PR
Test Plan
New fixtures