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

Prototype Black's string joining/splitting #4449

Merged
merged 4 commits into from
May 16, 2023
Merged

Conversation

MichaReiser
Copy link
Member

@MichaReiser MichaReiser commented May 16, 2023

This PR adds a test to verify that the fill element can be used to implement Black's string-processing

The "full" implementation needs to split all strings by words and create a single fill element for it. But that seems straightforward so that it isn't covered by this test.

@MichaReiser
Copy link
Member Author

Current dependencies on/for this PR:

This comment was auto-generated by Graphite.

let format_str = format_with(|f| {
write!(f, [text("\"")])?;

let mut words = self.0.split_whitespace().peekable();
Copy link
Member Author

Choose a reason for hiding this comment

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

The "real" implementation will need to be more careful to keep the number of whitespace between any two words the same. We can use [soft_line_break, if_group_fits(&text("<num_spaces>"))] to accomplish this.

@MichaReiser MichaReiser added the formatter Related to the formatter label May 16, 2023
@github-actions
Copy link
Contributor

github-actions bot commented May 16, 2023

PR Check Results

Ecosystem

✅ ecosystem check detected no changes.

Benchmark

Linux

group                                      main                                   pr
-----                                      ----                                   --
linter/all-rules/large/dataset.py          1.00     15.0±0.11ms     2.7 MB/sec    1.00     15.0±0.14ms     2.7 MB/sec
linter/all-rules/numpy/ctypeslib.py        1.00      3.7±0.01ms     4.5 MB/sec    1.00      3.7±0.01ms     4.5 MB/sec
linter/all-rules/numpy/globals.py          1.01    379.2±0.94µs     7.8 MB/sec    1.00    375.9±1.00µs     7.8 MB/sec
linter/all-rules/pydantic/types.py         1.00      6.2±0.04ms     4.1 MB/sec    1.00      6.2±0.02ms     4.1 MB/sec
linter/default-rules/large/dataset.py      1.00      7.4±0.02ms     5.5 MB/sec    1.01      7.5±0.03ms     5.4 MB/sec
linter/default-rules/numpy/ctypeslib.py    1.00   1558.0±4.47µs    10.7 MB/sec    1.01   1569.2±1.80µs    10.6 MB/sec
linter/default-rules/numpy/globals.py      1.00    166.7±0.29µs    17.7 MB/sec    1.01    168.3±0.86µs    17.5 MB/sec
linter/default-rules/pydantic/types.py     1.00      3.3±0.01ms     7.7 MB/sec    1.01      3.3±0.01ms     7.6 MB/sec
parser/large/dataset.py                    1.02      6.0±0.01ms     6.7 MB/sec    1.00      5.9±0.01ms     6.8 MB/sec
parser/numpy/ctypeslib.py                  1.02   1181.3±1.03µs    14.1 MB/sec    1.00   1163.0±0.97µs    14.3 MB/sec
parser/numpy/globals.py                    1.01    120.2±0.36µs    24.5 MB/sec    1.00    119.2±0.45µs    24.8 MB/sec
parser/pydantic/types.py                   1.02      2.6±0.00ms    10.0 MB/sec    1.00      2.5±0.00ms    10.2 MB/sec

Windows

group                                      main                                   pr
-----                                      ----                                   --
linter/all-rules/large/dataset.py          1.00     21.0±0.74ms  1985.6 KB/sec    1.00     21.0±0.63ms  1979.9 KB/sec
linter/all-rules/numpy/ctypeslib.py        1.01      5.3±0.17ms     3.2 MB/sec    1.00      5.2±0.20ms     3.2 MB/sec
linter/all-rules/numpy/globals.py          1.00   628.1±29.89µs     4.7 MB/sec    1.00   630.3±25.21µs     4.7 MB/sec
linter/all-rules/pydantic/types.py         1.00      8.7±0.38ms     2.9 MB/sec    1.02      8.8±0.33ms     2.9 MB/sec
linter/default-rules/large/dataset.py      1.00     10.1±0.42ms     4.0 MB/sec    1.02     10.2±0.26ms     4.0 MB/sec
linter/default-rules/numpy/ctypeslib.py    1.00      2.1±0.07ms     7.8 MB/sec    1.01      2.2±0.08ms     7.7 MB/sec
linter/default-rules/numpy/globals.py      1.00   247.9±10.21µs    11.9 MB/sec    1.05   260.4±16.82µs    11.3 MB/sec
linter/default-rules/pydantic/types.py     1.00      4.5±0.22ms     5.6 MB/sec    1.01      4.6±0.26ms     5.6 MB/sec
parser/large/dataset.py                    1.00      8.3±0.27ms     4.9 MB/sec    1.01      8.3±0.19ms     4.9 MB/sec
parser/numpy/ctypeslib.py                  1.00  1572.0±48.98µs    10.6 MB/sec    1.01  1586.1±44.22µs    10.5 MB/sec
parser/numpy/globals.py                    1.00    161.3±6.91µs    18.3 MB/sec    1.03    165.8±7.73µs    17.8 MB/sec
parser/pydantic/types.py                   1.00      3.5±0.10ms     7.3 MB/sec    1.00      3.5±0.09ms     7.3 MB/sec

@MichaReiser MichaReiser merged commit ddf7de7 into main May 16, 2023
15 checks passed
@MichaReiser MichaReiser deleted the string-processing-example branch May 16, 2023 17:42
MichaReiser pushed a commit that referenced this pull request Jul 27, 2023
Fix AST generated from a dict literal containing dict unpacking
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
formatter Related to the formatter
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants