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

Improve long values in dict literals #3440

Merged
merged 10 commits into from
Dec 15, 2022
Merged

Improve long values in dict literals #3440

merged 10 commits into from
Dec 15, 2022

Conversation

yilei
Copy link
Contributor

@yilei yilei commented Dec 14, 2022

Description

This PR changes the preview style:

Usually I'd like to keep the PR's scope minimal, but the lambda change & dict value change are depended by each other so it's hard to split into two PRs.

Checklist - did you ...

  • Add an entry in CHANGES.md if necessary?
  • Add / update tests if necessary?
  • Add new / update outdated documentation?

@github-actions
Copy link

github-actions bot commented Dec 14, 2022

diff-shades results comparing this PR (ba1b968) to main (a282181). The full diff is available in the logs under the "Generate HTML diff report" step.

╭───────────────────────── Summary ─────────────────────────╮
│ 10 projects & 99 files changed / 1089 changes [+608/-481] │
│                                                           │
│ ... out of 2 355 274 lines, 10 989 files & 23 projects    │
╰───────────────────────────────────────────────────────────╯

Differences found.

What is this? | Workflow run | diff-shades documentation

@JelleZijlstra
Copy link
Collaborator

Notes from diff-shades:

             queryset = queryset.extra(
                 select={
                     "_prefetch_related_val_%s"
-                    % f.attname: "%s.%s"
-                    % (qn(join_table), qn(f.column))
+                    % f.attname: "%s.%s" % (qn(join_table), qn(f.column))
                     for f in fk.local_related_fields
                 }
             )

Note that both the key and the value in the dictcomp use % formatting. Looks a little weird, maybe we should put the key and value on separate lines. Seems out of scope for this PR though.

Pandas has a similarly odd-looking case with a + in the key:

         tests = [
             (
                 BusinessHour(),
                 {
                     Timestamp("2014-07-04 15:00")
-                    + Nano(5): Timestamp("2014-07-04 16:00")
-                    + Nano(5),
+                    + Nano(5): Timestamp("2014-07-04 16:00") + Nano(5),
                     Timestamp("2014-07-04 16:00")
-                    + Nano(5): Timestamp("2014-07-07 09:00")
-                    + Nano(5),
+                    + Nano(5): Timestamp("2014-07-07 09:00") + Nano(5),
                     Timestamp("2014-07-04 16:00")
-                    - Nano(5): Timestamp("2014-07-04 17:00")
-                    - Nano(5),
+                    - Nano(5): Timestamp("2014-07-04 17:00") - Nano(5),
                 },
             ),

Otherwise I like the changes from the PR: they make it easier to see when one dict key ends and the next one begins, because values get indented.

Copy link
Collaborator

@JelleZijlstra JelleZijlstra left a comment

Choose a reason for hiding this comment

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

thanks, just noticed two typos

src/black/trans.py Outdated Show resolved Hide resolved
src/black/trans.py Outdated Show resolved Hide resolved
yilei and others added 2 commits December 14, 2022 22:10
Co-authored-by: Jelle Zijlstra <[email protected]>
Co-authored-by: Jelle Zijlstra <[email protected]>
@yilei
Copy link
Contributor Author

yilei commented Dec 15, 2022

Thanks for the review! Agreed above two examples are out of scope from this PR, they concern the dict keys. Opened #3442 separately.

@JelleZijlstra JelleZijlstra merged commit 658c8d8 into psf:main Dec 15, 2022
@yilei yilei deleted the strcrash branch December 16, 2022 01:44
@yilei yilei mentioned this pull request Dec 16, 2022
3 tasks
yilei added a commit to yilei/black that referenced this pull request Feb 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants