Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format call expressions (without call chaining) #5341

Merged
merged 5 commits into from
Jun 27, 2023

Conversation

konstin
Copy link
Member

@konstin konstin commented Jun 23, 2023

Summary

This formats call expressions with magic trailing comma and parentheses behaviour but without call chaining

Test Plan

Lots of new test fixtures, including some that don't work yet

@konstin
Copy link
Member Author

konstin commented Jun 23, 2023

Current dependencies on/for this PR:

This comment was auto-generated by Graphite.

@konstin konstin changed the title Format call expressions (without call chaining)Format call expressions, without call chaining and inefficiently, to fix an invalid syntax bug Format call expressions (without call chaining) Jun 23, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Jun 23, 2023

PR Check Results

Ecosystem

✅ ecosystem check detected no changes.

Benchmark

Linux

group                                      main                                   pr
-----                                      ----                                   --
formatter/large/dataset.py                 1.00     10.1±0.43ms     4.0 MB/sec    1.01     10.2±0.26ms     4.0 MB/sec
formatter/numpy/ctypeslib.py               1.00      2.1±0.10ms     8.0 MB/sec    1.02      2.1±0.05ms     7.9 MB/sec
formatter/numpy/globals.py                 1.00    241.0±7.76µs    12.2 MB/sec    1.04    250.7±8.35µs    11.8 MB/sec
formatter/pydantic/types.py                1.00      4.6±0.13ms     5.6 MB/sec    1.01      4.6±0.12ms     5.5 MB/sec
linter/all-rules/large/dataset.py          1.00     16.9±0.59ms     2.4 MB/sec    1.07     18.0±0.45ms     2.3 MB/sec
linter/all-rules/numpy/ctypeslib.py        1.00      4.3±0.16ms     3.9 MB/sec    1.01      4.3±0.13ms     3.8 MB/sec
linter/all-rules/numpy/globals.py          1.02   563.8±19.95µs     5.2 MB/sec    1.00   552.9±16.93µs     5.3 MB/sec
linter/all-rules/pydantic/types.py         1.00      7.7±0.26ms     3.3 MB/sec    1.03      7.9±0.23ms     3.2 MB/sec
linter/default-rules/large/dataset.py      1.00      8.7±0.22ms     4.7 MB/sec    1.02      8.9±0.33ms     4.6 MB/sec
linter/default-rules/numpy/ctypeslib.py    1.00  1811.2±57.99µs     9.2 MB/sec    1.05  1898.7±45.91µs     8.8 MB/sec
linter/default-rules/numpy/globals.py      1.00   221.8±15.72µs    13.3 MB/sec    1.00    222.0±5.77µs    13.3 MB/sec
linter/default-rules/pydantic/types.py     1.00      4.0±0.12ms     6.4 MB/sec    1.01      4.0±0.08ms     6.4 MB/sec

Windows

group                                      main                                   pr
-----                                      ----                                   --
formatter/large/dataset.py                 1.00      9.3±0.14ms     4.4 MB/sec    1.00      9.2±0.05ms     4.4 MB/sec
formatter/numpy/ctypeslib.py               1.00  1927.9±17.84µs     8.6 MB/sec    1.00  1919.1±41.92µs     8.7 MB/sec
formatter/numpy/globals.py                 1.00    209.2±1.79µs    14.1 MB/sec    1.00    210.0±4.64µs    14.1 MB/sec
formatter/pydantic/types.py                1.01      4.4±0.04ms     5.8 MB/sec    1.00      4.4±0.03ms     5.9 MB/sec
linter/all-rules/large/dataset.py          1.00     15.6±0.14ms     2.6 MB/sec    1.00     15.5±0.14ms     2.6 MB/sec
linter/all-rules/numpy/ctypeslib.py        1.01      4.1±0.04ms     4.0 MB/sec    1.00      4.1±0.02ms     4.0 MB/sec
linter/all-rules/numpy/globals.py          1.02    437.8±8.96µs     6.7 MB/sec    1.00    431.3±5.71µs     6.8 MB/sec
linter/all-rules/pydantic/types.py         1.00      6.9±0.07ms     3.7 MB/sec    1.00      6.9±0.06ms     3.7 MB/sec
linter/default-rules/large/dataset.py      1.00      8.1±0.04ms     5.0 MB/sec    1.00      8.1±0.06ms     5.0 MB/sec
linter/default-rules/numpy/ctypeslib.py    1.00   1668.2±9.60µs    10.0 MB/sec    1.02  1709.1±26.57µs     9.7 MB/sec
linter/default-rules/numpy/globals.py      1.00    180.0±1.25µs    16.4 MB/sec    1.00    179.3±1.19µs    16.5 MB/sec
linter/default-rules/pydantic/types.py     1.00      3.6±0.05ms     7.0 MB/sec    1.00      3.6±0.02ms     7.0 MB/sec

@konstin konstin force-pushed the fix_attribute_chain_own_line_comments_rebased branch from 37fdcdd to 8bc2b89 Compare June 26, 2023 09:05
Base automatically changed from fix_attribute_chain_own_line_comments_rebased to main June 26, 2023 09:13
@konstin konstin force-pushed the call_expressions_no_call_chaining branch 2 times, most recently from c15c45a to ebf1c09 Compare June 26, 2023 12:04
@konstin konstin marked this pull request as ready for review June 26, 2023 12:04
Cargo.toml Outdated
Comment on lines 62 to 66
#ruff_text_size = { path = "../disk/projects/RustPython-Parser/ruff_text_size" }
#rustpython-ast = { path = "../disk/projects/RustPython-Parser/ast", default-features = false, features = ["num-bigint"] }
#rustpython-format = { path = "../disk/projects/RustPython-Parser/format", default-features = false, features = ["num-bigint"] }
#rustpython-literal = { path = "../disk/projects/RustPython-Parser/literal", default-features = false }
#rustpython-parser = { path = "../disk/projects/RustPython-Parser/parser", default-features = false, features = ["full-lexer", "num-bigint"] }
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'll remove this before merging

Copy link
Member

@MichaReiser MichaReiser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! What's the plan with the failing tests? Do you plan to comment them out for now? Would it help if I took a look (unlikely to be before Wednesday)?

if let Some(arg) = arg {
write!(f, [arg.format(), text("="), value.format()])
} else {
// TODO(konstin): dangling comments after the stars?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that we have to preserve these. It seems a rather weird place to put comments.

@@ -13,10 +13,11 @@ impl FormatNodeRule<Keyword> for FormatKeyword {
arg,
value,
} = item;
if let Some(argument) = arg {
write!(f, [argument.format(), text("=")])?;
if let Some(arg) = arg {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I prefer to move the logic that is common for all branches out of the if. I find that this improves readability. I otherwise have to manually parse both branches to understand what's the same/different.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i want to keep those two specifically since they are one entry in a list each and because each branch has its own comment handling

Comment on lines +1076 to +1091
// value . attr
// ^^^^^^^ the range of dangling comments
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@konstin konstin force-pushed the call_expressions_no_call_chaining branch from ebf1c09 to 9a63e21 Compare June 27, 2023 07:29
@konstin konstin enabled auto-merge (squash) June 27, 2023 09:26
@konstin konstin merged commit 7f6cb9d into main Jun 27, 2023
@konstin konstin deleted the call_expressions_no_call_chaining branch June 27, 2023 09:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants