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

Add basic Constant formatting #4954

Merged
merged 1 commit into from
Jun 8, 2023
Merged

Add basic Constant formatting #4954

merged 1 commit into from
Jun 8, 2023

Conversation

MichaReiser
Copy link
Member

Summary

This PR adds basic formatting for Constant instead of replacing all of them with 042.

The PR doesn't aim at implementing the proper formatting for Constants

Test Plan

cargo test

@MichaReiser MichaReiser requested a review from konstin June 8, 2023 10:42
@MichaReiser MichaReiser added internal An internal refactor or improvement formatter Related to the formatter labels Jun 8, 2023
@MichaReiser MichaReiser force-pushed the basic-const-formatting branch from f297b7f to bab81d7 Compare June 8, 2023 10:57
@MichaReiser MichaReiser force-pushed the basic-const-formatting branch from bab81d7 to f42af55 Compare June 8, 2023 11:05
@konstin
Copy link
Member

konstin commented Jun 8, 2023

i was trying the same thing 😅

        match item {
            Constant::None => text("None").fmt(f),
            Constant::Bool(b) => {
                if *b {
                    text("True").fmt(f)
                } else {
                    text("False").fmt(f)
                }
            }
            Constant::Str(s) => text(r#""NOT_IMPLEMENTED_string""#).fmt(f),
            Constant::Bytes(b) => text(r#""NOT_IMPLEMENTED_bytes""#).fmt(f),
            Constant::Int(i) => dynamic_text(&i.to_string(), Some(self.0.start())).fmt(f),
            Constant::Tuple(tup) => {
                if let [single_element] = &tup[..] {
                    single_element.format().fmt(f)
                } else {
                    format_with(|f| {
                        f.join_with(format_args!(text(","), soft_line_break_or_space()))
                            .entries(tup.iter().formatted())
                            .finish()
                    })
                    .fmt(f)
                }
            }
            Constant::Float(fp) => dynamic_text(&fp.to_string(), Some(self.0.start())).fmt(f),
            Constant::Complex { real, imag } => text(r#""NOT_IMPLEMENTED_complex""#).fmt(f),
            Constant::Ellipsis => text("...").fmt(f),
        }

@github-actions
Copy link
Contributor

github-actions bot commented Jun 8, 2023

PR Check Results

Ecosystem

✅ ecosystem check detected no changes.

Benchmark

Linux

group                                      main                                   pr
-----                                      ----                                   --
formatter/large/dataset.py                 1.00      6.4±0.05ms     6.3 MB/sec    1.00      6.4±0.05ms     6.3 MB/sec
formatter/numpy/ctypeslib.py               1.00  1285.8±10.66µs    12.9 MB/sec    1.01  1295.9±11.03µs    12.8 MB/sec
formatter/numpy/globals.py                 1.00    149.3±1.37µs    19.8 MB/sec    1.00    149.6±1.68µs    19.7 MB/sec
formatter/pydantic/types.py                1.00      2.9±0.03ms     8.8 MB/sec    1.00      2.9±0.01ms     8.8 MB/sec
linter/all-rules/large/dataset.py          1.00     16.3±0.47ms     2.5 MB/sec    1.02     16.6±0.31ms     2.4 MB/sec
linter/all-rules/numpy/ctypeslib.py        1.00      3.9±0.05ms     4.2 MB/sec    1.02      4.0±0.06ms     4.2 MB/sec
linter/all-rules/numpy/globals.py          1.00    485.6±5.70µs     6.1 MB/sec    1.01    491.2±5.99µs     6.0 MB/sec
linter/all-rules/pydantic/types.py         1.00      6.9±0.08ms     3.7 MB/sec    1.01      6.9±0.15ms     3.7 MB/sec
linter/default-rules/large/dataset.py      1.00      7.9±0.10ms     5.1 MB/sec    1.02      8.1±0.16ms     5.0 MB/sec
linter/default-rules/numpy/ctypeslib.py    1.00  1708.7±17.52µs     9.7 MB/sec    1.02  1739.9±26.83µs     9.6 MB/sec
linter/default-rules/numpy/globals.py      1.00    185.2±3.26µs    15.9 MB/sec    1.01    187.9±1.96µs    15.7 MB/sec
linter/default-rules/pydantic/types.py     1.00      3.6±0.04ms     7.1 MB/sec    1.02      3.6±0.03ms     7.0 MB/sec

Windows

group                                      main                                   pr
-----                                      ----                                   --
formatter/large/dataset.py                 1.01      6.7±0.10ms     6.0 MB/sec    1.00      6.7±0.07ms     6.1 MB/sec
formatter/numpy/ctypeslib.py               1.01  1324.5±20.09µs    12.6 MB/sec    1.00  1314.2±18.14µs    12.7 MB/sec
formatter/numpy/globals.py                 1.00    151.6±2.35µs    19.5 MB/sec    1.00    151.2±3.41µs    19.5 MB/sec
formatter/pydantic/types.py                1.00      3.0±0.05ms     8.5 MB/sec    1.00      3.0±0.04ms     8.5 MB/sec
linter/all-rules/large/dataset.py          1.01     17.0±0.22ms     2.4 MB/sec    1.00     16.9±0.20ms     2.4 MB/sec
linter/all-rules/numpy/ctypeslib.py        1.00      4.3±0.05ms     3.9 MB/sec    1.00      4.3±0.06ms     3.9 MB/sec
linter/all-rules/numpy/globals.py          1.03   508.4±11.07µs     5.8 MB/sec    1.00    493.5±8.90µs     6.0 MB/sec
linter/all-rules/pydantic/types.py         1.02      7.2±0.12ms     3.5 MB/sec    1.00      7.1±0.08ms     3.6 MB/sec
linter/default-rules/large/dataset.py      1.00      8.3±0.08ms     4.9 MB/sec    1.00      8.3±0.11ms     4.9 MB/sec
linter/default-rules/numpy/ctypeslib.py    1.00  1765.1±23.58µs     9.4 MB/sec    1.00  1761.7±19.60µs     9.5 MB/sec
linter/default-rules/numpy/globals.py      1.01    200.6±4.00µs    14.7 MB/sec    1.00    198.4±3.71µs    14.9 MB/sec
linter/default-rules/pydantic/types.py     1.01      3.8±0.05ms     6.8 MB/sec    1.00      3.7±0.04ms     6.8 MB/sec

@MichaReiser MichaReiser closed this Jun 8, 2023
@MichaReiser MichaReiser reopened this Jun 8, 2023
@MichaReiser MichaReiser enabled auto-merge (squash) June 8, 2023 11:36
@MichaReiser
Copy link
Member Author

i was trying the same thing sweat_smile

        match item {
            Constant::None => text("None").fmt(f),
            Constant::Bool(b) => {
                if *b {
                    text("True").fmt(f)
                } else {
                    text("False").fmt(f)
                }
            }
            Constant::Str(s) => text(r#""NOT_IMPLEMENTED_string""#).fmt(f),
            Constant::Bytes(b) => text(r#""NOT_IMPLEMENTED_bytes""#).fmt(f),
            Constant::Int(i) => dynamic_text(&i.to_string(), Some(self.0.start())).fmt(f),
            Constant::Tuple(tup) => {
                if let [single_element] = &tup[..] {
                    single_element.format().fmt(f)
                } else {
                    format_with(|f| {
                        f.join_with(format_args!(text(","), soft_line_break_or_space()))
                            .entries(tup.iter().formatted())
                            .finish()
                    })
                    .fmt(f)
                }
            }
            Constant::Float(fp) => dynamic_text(&fp.to_string(), Some(self.0.start())).fmt(f),
            Constant::Complex { real, imag } => text(r#""NOT_IMPLEMENTED_complex""#).fmt(f),
            Constant::Ellipsis => text("...").fmt(f),
        }

Oh no, I'm sorry. Took me a while to figure out why the expression.py was failing...

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.

2 participants