Skip to content

Format Attribute Expression#5259

Merged
MichaReiser merged 1 commit intomainfrom
format-attribute-expression
Jun 21, 2023
Merged

Format Attribute Expression#5259
MichaReiser merged 1 commit intomainfrom
format-attribute-expression

Conversation

@MichaReiser
Copy link
Member

Summary

This PR adds basic formatting for attribute expressions (a.b).

Test Plan

I added a file with new attribute tests (especially around comments)

@MichaReiser
Copy link
Member Author

Current dependencies on/for this PR:

This comment was auto-generated by Graphite.

@MichaReiser MichaReiser requested a review from konstin June 21, 2023 16:45
@MichaReiser MichaReiser added internal An internal refactor or improvement formatter Related to the formatter labels Jun 21, 2023
@MichaReiser MichaReiser linked an issue Jun 21, 2023 that may be closed by this pull request
@MichaReiser MichaReiser force-pushed the format-attribute-expression branch from 6a52fda to 66fcb55 Compare June 21, 2023 16:47
@github-actions
Copy link
Contributor

github-actions bot commented Jun 21, 2023

PR Check Results

Ecosystem

✅ ecosystem check detected no changes.

Benchmark

Linux

group                                      main                                   pr
-----                                      ----                                   --
formatter/large/dataset.py                 1.20      8.4±0.05ms     4.9 MB/sec    1.00      7.0±0.02ms     5.8 MB/sec
formatter/numpy/ctypeslib.py               1.15   1648.9±3.23µs    10.1 MB/sec    1.00   1428.8±3.29µs    11.7 MB/sec
formatter/numpy/globals.py                 1.12    149.7±1.11µs    19.7 MB/sec    1.00    133.4±0.26µs    22.1 MB/sec
formatter/pydantic/types.py                1.17      3.4±0.01ms     7.5 MB/sec    1.00      2.9±0.01ms     8.9 MB/sec
linter/all-rules/large/dataset.py          1.00     13.7±0.03ms     3.0 MB/sec    1.00     13.6±0.11ms     3.0 MB/sec
linter/all-rules/numpy/ctypeslib.py        1.01      3.5±0.00ms     4.8 MB/sec    1.00      3.4±0.01ms     4.8 MB/sec
linter/all-rules/numpy/globals.py          1.00    365.5±0.81µs     8.1 MB/sec    1.00    366.5±2.97µs     8.1 MB/sec
linter/all-rules/pydantic/types.py         1.00      6.0±0.02ms     4.2 MB/sec    1.01      6.1±0.07ms     4.2 MB/sec
linter/default-rules/large/dataset.py      1.00      7.0±0.01ms     5.8 MB/sec    1.00      7.0±0.03ms     5.8 MB/sec
linter/default-rules/numpy/ctypeslib.py    1.00   1467.3±5.81µs    11.3 MB/sec    1.00   1462.2±2.90µs    11.4 MB/sec
linter/default-rules/numpy/globals.py      1.00    154.9±0.67µs    19.1 MB/sec    1.00    154.2±0.35µs    19.1 MB/sec
linter/default-rules/pydantic/types.py     1.01      3.2±0.00ms     8.0 MB/sec    1.00      3.2±0.00ms     8.0 MB/sec

Windows

group                                      main                                   pr
-----                                      ----                                   --
formatter/large/dataset.py                 1.02     10.7±0.30ms     3.8 MB/sec    1.00     10.4±0.51ms     3.9 MB/sec
formatter/numpy/ctypeslib.py               1.04      2.2±0.08ms     7.6 MB/sec    1.00      2.1±0.08ms     7.9 MB/sec
formatter/numpy/globals.py                 1.02   224.3±20.55µs    13.2 MB/sec    1.00   220.7±13.75µs    13.4 MB/sec
formatter/pydantic/types.py                1.04      4.4±0.17ms     5.8 MB/sec    1.00      4.2±0.13ms     6.0 MB/sec
linter/all-rules/large/dataset.py          1.00     19.3±0.46ms     2.1 MB/sec    1.04     20.0±0.93ms     2.0 MB/sec
linter/all-rules/numpy/ctypeslib.py        1.00      5.1±0.18ms     3.2 MB/sec    1.01      5.2±0.18ms     3.2 MB/sec
linter/all-rules/numpy/globals.py          1.00   619.5±23.69µs     4.8 MB/sec    1.08   666.0±39.21µs     4.4 MB/sec
linter/all-rules/pydantic/types.py         1.00      8.6±0.25ms     2.9 MB/sec    1.01      8.7±0.26ms     2.9 MB/sec
linter/default-rules/large/dataset.py      1.00     10.4±0.52ms     3.9 MB/sec    1.03     10.7±0.43ms     3.8 MB/sec
linter/default-rules/numpy/ctypeslib.py    1.00      2.2±0.07ms     7.7 MB/sec    1.03      2.2±0.11ms     7.5 MB/sec
linter/default-rules/numpy/globals.py      1.00   261.4±14.00µs    11.3 MB/sec    1.02   266.0±10.08µs    11.1 MB/sec
linter/default-rules/pydantic/types.py     1.00      4.7±0.35ms     5.4 MB/sec    1.00      4.7±0.16ms     5.4 MB/sec

Copy link
Member

@konstin konstin left a comment

Choose a reason for hiding this comment

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

this will make a lot more real world code formatted

text("."),
not_yet_implemented_custom_text("NOT_IMPLEMENTED_attr")
trailing_comments(trailing_dot_comments),
(!leading_attribute_comments.is_empty()).then_some(hard_line_break()),
Copy link
Member

Choose a reason for hiding this comment

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

oh i didn't realize write would take an option

Copy link
Member Author

@MichaReiser MichaReiser Jun 21, 2023

Choose a reason for hiding this comment

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

You can also pass an empty tuple. Don't know when that's useful but it's implemented ;) I even thought that Format is implemented for FormatResult<T> but that doesn't seem to be the case.

@MichaReiser MichaReiser force-pushed the format-attribute-expression branch from 66fcb55 to b224ea9 Compare June 21, 2023 20:36
@MichaReiser MichaReiser force-pushed the format-attribute-expression branch from b224ea9 to 2c7d10a Compare June 21, 2023 21:23
@MichaReiser MichaReiser enabled auto-merge (squash) June 21, 2023 21:26
@MichaReiser MichaReiser merged commit ccf34aa into main Jun 21, 2023
@MichaReiser MichaReiser deleted the format-attribute-expression branch June 21, 2023 21:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

formatter Related to the formatter internal An internal refactor or improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Formatter: Attribute

2 participants