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

Fix: Avoid parenthesizing subscript targets and values #9209

Merged
merged 1 commit into from
Dec 20, 2023

Conversation

MichaReiser
Copy link
Member

@MichaReiser MichaReiser commented Dec 20, 2023

Summary

Avoid adding parentheses around assignment targets that contain subscripts and use the best fit layout for attribute chains containing subscripts.

Fixes #9112

Test Plan

Verified that the ecosystem changes now match black.

@MichaReiser MichaReiser added formatter Related to the formatter preview Related to preview mode features labels Dec 20, 2023
Copy link
Contributor

github-actions bot commented Dec 20, 2023

ruff-ecosystem results

Formatter (stable)

✅ ecosystem check detected no format changes.

Formatter (preview)

ℹ️ ecosystem check detected format changes. (+15 -20 lines in 5 files in 3 projects; 38 projects unchanged)

pandas-dev/pandas (+3 -3 lines across 1 file)

ruff format --preview

pandas/core/reshape/melt.py~L122

     if frame.shape[1] > 0 and not any(
         not isinstance(dt, np.dtype) and dt._supports_2d for dt in frame.dtypes
     ):
-        mdata[value_name] = (
-            concat([frame.iloc[:, i] for i in range(frame.shape[1])]).values
-        )
+        mdata[value_name] = concat([
+            frame.iloc[:, i] for i in range(frame.shape[1])
+        ]).values
     else:
         mdata[value_name] = frame._values.ravel("F")
     for i, col in enumerate(var_name):

tiangolo/fastapi (+3 -3 lines across 1 file)

ruff format --preview

fastapi/dependencies/utils.py~L343

             if isinstance(arg, (params.Param, params.Body, params.Depends))
         ]
         if fastapi_specific_annotations:
-            fastapi_annotation: Union[
-                FieldInfo, params.Depends, None
-            ] = fastapi_specific_annotations[-1]
+            fastapi_annotation: Union[FieldInfo, params.Depends, None] = (
+                fastapi_specific_annotations[-1]
+            )
         else:
             fastapi_annotation = None
         if isinstance(fastapi_annotation, FieldInfo):

zulip/zulip (+9 -14 lines across 3 files)

ruff format --preview

zerver/lib/message.py~L458

             # sender's user ID.
             obj["sender_full_name"] = str(UserProfile.INACCESSIBLE_USER_NAME)
             sender_id = obj["sender_id"]
-            obj["sender_email"] = (
-                Address(
-                    username=f"user{sender_id}", domain=get_fake_email_domain(realm_host)
-                ).addr_spec
-            )
+            obj["sender_email"] = Address(
+                username=f"user{sender_id}", domain=get_fake_email_domain(realm_host)
+            ).addr_spec
 
         MessageDict.set_sender_avatar(obj, client_gravatar, can_access_sender)
         if apply_markdown:

zerver/lib/push_notifications.py~L961

         # inaccessible user as we allow unsubscribed users to send
         # messages to streams. For direct messages, the guest gains
         # access to the user if they where previously inaccessible.
-        data["sender_email"] = (
-            Address(
-                username=f"user{message.sender.id}",
-                domain=get_fake_email_domain(message.realm.host),
-            ).addr_spec
-        )
+        data["sender_email"] = Address(
+            username=f"user{message.sender.id}", domain=get_fake_email_domain(message.realm.host)
+        ).addr_spec
     else:
         data["sender_email"] = message.sender.email
 

zerver/lib/users.py~L747

     for user_id in target_user_ids:
         target_user_subbed_recipients = target_user_subscriptions_dict[user_id]
         for recipient_id in target_user_subbed_recipients:
-            users_subbed_to_target_user_subscriptions_dict[
-                user_id
-            ] |= subscribers_dict_by_recipient_ids[recipient_id]
+            users_subbed_to_target_user_subscriptions_dict[user_id] |= (
+                subscribers_dict_by_recipient_ids[recipient_id]
+            )
 
     return users_subbed_to_target_user_subscriptions_dict
 

@MichaReiser MichaReiser marked this pull request as draft December 20, 2023 08:02
@MichaReiser MichaReiser force-pushed the fix-avoid-parenthesizing-attribute-chains branch from e976456 to 240a488 Compare December 20, 2023 08:33
Signed-off-by: Micha Reiser <micha@reiser.io>
@MichaReiser MichaReiser force-pushed the fix-avoid-parenthesizing-attribute-chains branch from 240a488 to 1b4295a Compare December 20, 2023 10:14
@MichaReiser MichaReiser marked this pull request as ready for review December 20, 2023 10:15
@MichaReiser MichaReiser merged commit ef4bd8d into main Dec 20, 2023
17 checks passed
@MichaReiser MichaReiser deleted the fix-avoid-parenthesizing-attribute-chains branch December 20, 2023 23:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
formatter Related to the formatter preview Related to preview mode features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Prefer splitting right hand side of assignment first: Unnecessary parentheses
2 participants