ruff icon indicating copy to clipboard operation
ruff copied to clipboard

Indent nested binary expressions

Open MichaReiser opened this issue 1 year ago • 1 comments

Summary

This isn't it yet... and in no way what we recommend going forward. This PR is just me playing around with some different formatting and to see what works and what doesn't.

The formatting of very long binary expression improves but there are now many cases where the indent feels too deep and breaking before the + operator feels wrong. We probably need to become clever of when and when not to insert the line break when indenting as well

This is a good ecosystem stress test :laughing: This also raises the question if something as fundamental as binary expression formatting can still be changed...

Test Plan

MichaReiser avatar Feb 14 '24 17:02 MichaReiser

ruff-ecosystem results

Formatter (stable)

ℹ️ ecosystem check detected format changes. (+6766 -6660 lines in 1009 files in 29 projects; 14 projects unchanged)

DisnakeDev/disnake (+35 -35 lines across 8 files)

disnake/audit_logs.py~L601

                 self.extra = type("_AuditLogProxy", (), elems)()
             elif (
                 self.action is enums.AuditLogAction.member_move
-                or self.action is enums.AuditLogAction.message_delete
+                    or self.action is enums.AuditLogAction.message_delete
             ):
                 elems = {
                     "count": int(extra["count"]),

disnake/audit_logs.py~L844

     ) -> Union[GuildScheduledEvent, Object]:
         return (
             self.guild.get_scheduled_event(target_id)
-            or self._guild_scheduled_events.get(target_id)
-            or Object(id=target_id)
+                or self._guild_scheduled_events.get(target_id)
+                or Object(id=target_id)
         )
 
     def _convert_target_application_command_or_integration(

disnake/audit_logs.py~L854

         # try application command
         if target := (
             self._state._get_guild_application_command(self.guild.id, target_id)
-            or self._state._get_global_application_command(target_id)
-            or self._application_commands.get(target_id)
+                or self._state._get_global_application_command(target_id)
+                or self._application_commands.get(target_id)
         ):
             return target
 

disnake/channel.py~L1999

             member
             for member in self.members
             if member.voice
-            and not member.voice.suppress
-            and member.voice.requested_to_speak_at is None
+                and not member.voice.suppress
+                and member.voice.requested_to_speak_at is None
         ]
 
     @property

disnake/ext/commands/core.py~L552

             except ArgumentParsingError:
                 if (
                     self._is_typing_optional(param.annotation)
-                    and not param.kind == param.VAR_POSITIONAL
+                        and not param.kind == param.VAR_POSITIONAL
                 ):
                     view.index = previous
                     return None

disnake/ext/commands/core.py~L2490

                     disnake.StageChannel,
                 ),
             )
-            and ch.is_nsfw()
+                and ch.is_nsfw()
         ):
             return True
         raise NSFWChannelRequired(ch)  # type: ignore

disnake/ext/commands/interaction_bot_base.py~L160

 
         if command_sync_flags is not None and (
             sync_commands is not MISSING
-            or sync_commands_debug is not MISSING
-            or sync_commands_on_cog_unload is not MISSING
+                or sync_commands_debug is not MISSING
+                or sync_commands_on_cog_unload is not MISSING
         ):
             raise TypeError(
                 "cannot set 'command_sync_flags' and any of 'sync_commands', 'sync_commands_debug', 'sync_commands_on_cog_unload' at the same time."

disnake/ext/commands/interaction_bot_base.py~L891

 
         if (
             not self._command_sync_flags._sync_enabled
-            or self._sync_queued.locked()
-            or not self.is_ready()
-            or self._is_closed
-            or self.loop.is_closed()
+                or self._sync_queued.locked()
+                or not self.is_ready()
+                or self._is_closed
+                or self.loop.is_closed()
         ):
             return
         # We don't do this task on login or in parallel with a similar task

disnake/ext/commands/interaction_bot_base.py~L1314

             # if we're not currently syncing,
             not self._sync_queued.locked()
             # and we're instructed to sync guild commands
-            and self._command_sync_flags.sync_guild_commands
-            # and the current command was registered to a guild
-            and interaction.data.get("guild_id")
-            # and we don't know the command
-            and not self.get_guild_command(interaction.guild_id, interaction.data.id)  # type: ignore
+                and self._command_sync_flags.sync_guild_commands
+                # and the current command was registered to a guild
+                and interaction.data.get("guild_id")
+                # and we don't know the command
+                and not self.get_guild_command(interaction.guild_id, interaction.data.id)  # type: ignore
         ):
             # don't do anything if we aren't allowed to disable them
             if self._command_sync_flags.allow_command_deletion:

disnake/ext/commands/params.py~L643

         # If we received a `User` but didn't expect one, raise.
         if (
             isinstance(argument, disnake.User)
-            and issubclass_(self.type, disnake.Member)
-            and not issubclass_(self.type, disnake.User)
+                and issubclass_(self.type, disnake.Member)
+                and not issubclass_(self.type, disnake.User)
         ):
             raise errors.MemberNotFound(str(argument.id))
 

disnake/ext/commands/params.py~L703

         if not converter_mode:
             self.converter = (
                 self.converter
-                or getattr(annotation, "__discord_converter__", None)
-                or self._registered_converters.get(annotation)
+                    or getattr(annotation, "__discord_converter__", None)
+                    or self._registered_converters.get(annotation)
             )
             if self.converter:
                 self.parse_converter_annotation(self.converter, annotation)

disnake/ext/commands/params.py~L735

             self.type = annotation
         elif (
             isinstance(annotation, (EnumMeta, disnake.enums.EnumMeta))
-            or get_origin(annotation) is Literal
+                or get_origin(annotation) is Literal
         ):
             self._parse_enum(annotation)
         elif get_origin(annotation) in (Union, UnionType):

disnake/guild.py~L2278

 
         if (
             community is not MISSING
-            or invites_disabled is not MISSING
-            or raid_alerts_disabled is not MISSING
+                or invites_disabled is not MISSING
+                or raid_alerts_disabled is not MISSING
         ):
             # If we don't have complete feature information for the guild,
             # it is possible to disable or enable other features that we didn't intend to touch.

disnake/invite.py~L440

         # if it was stored on the Guild object, we would be throwing away this data from the api request
         if (
             self.guild is not None
-            and (guild_data := data.get("guild"))
-            and "welcome_screen" in guild_data
+                and (guild_data := data.get("guild"))
+                and "welcome_screen" in guild_data
         ):
             self.guild_welcome_screen: Optional[WelcomeScreen] = WelcomeScreen(
                 state=self._state,

disnake/state.py~L585

         # If presences are enabled then we get back the old guild.large behaviour
         return (
             self._chunk_guilds
-            and not guild.chunked
-            and not (self._intents.presences and not guild.large)
+                and not guild.chunked
+                and not (self._intents.presences and not guild.large)
         )
 
     def _get_guild_channel(

disnake/state.py~L767

             # This mirrors the current client and API behavior.
             if channel.__class__ is Thread and not (
                 message.type is MessageType.thread_starter_message
-                or (
-                    type(channel.parent) in (ForumChannel, MediaChannel)  # type: ignore
-                    and channel.id == message.id
-                )
+                    or (
+                        type(channel.parent) in (ForumChannel, MediaChannel)  # type: ignore
+                            and channel.id == message.id
+                    )
             ):
                 channel.total_message_sent += 1  # type: ignore
                 channel.message_count += 1  # type: ignore
PostHog/HouseWatch (+3 -1 lines across 1 file)

housewatch/clickhouse/table.py~L5

     QUERY = """SELECT engine FROM system.tables WHERE database = '%(database)s' AND name = '%(table)s'"""
     return (
         "replicated"
-        in run_query(QUERY, {"database": database, "table": table})[0]["engine"].lower()
+            in run_query(QUERY, {"database": database, "table": table})[0][
+                "engine"
+            ].lower()
     )
 
 
RasaHQ/rasa (+475 -470 lines across 68 files)

rasa/cli/export.py~L134

 
     if (
         min_timestamp is not None
-        and max_timestamp is not None
-        and max_timestamp < min_timestamp
+            and max_timestamp is not None
+            and max_timestamp < min_timestamp
     ):
         rasa.shared.utils.cli.print_error_and_exit(
             f"Maximum timestamp '{max_timestamp}' is smaller than minimum "

rasa/core/actions/action.py~L184

 
     if (
         action_name_or_text in defaults
-        and action_name_or_text not in domain.user_actions_and_forms
+            and action_name_or_text not in domain.user_actions_and_forms
     ):
         return defaults[action_name_or_text]
 

rasa/core/actions/action.py~L428

 
         if (
             self.intent_name_from_action(self.action_name)
-            in response_selector_properties
+                in response_selector_properties
         ):
             query_key = self.intent_name_from_action(self.action_name)
         elif RESPONSE_SELECTOR_DEFAULT_INTENT in response_selector_properties:

rasa/core/actions/action.py~L462

 
         if (
             self.intent_name_from_action(self.action_name)
-            in response_selector_properties
+                in response_selector_properties
         ):
             query_key = self.intent_name_from_action(self.action_name)
         elif RESPONSE_SELECTOR_DEFAULT_INTENT in response_selector_properties:

rasa/core/actions/action.py~L680

 
         if (
             not self._is_selective_domain_enabled()
-            or domain.does_custom_action_explicitly_need_domain(self.name())
+                or domain.does_custom_action_explicitly_need_domain(self.name())
         ):
             result["domain"] = domain.as_dict()
 

rasa/core/actions/action.py~L1022

         )
         if (
             intent_to_affirm == DEFAULT_NLU_FALLBACK_INTENT_NAME
-            and len(intent_ranking) > 1
+                and len(intent_ranking) > 1
         ):
             intent_to_affirm = intent_ranking[1][INTENT_NAME_KEY]  # type: ignore[literal-required] # noqa: E501
 

rasa/core/actions/action.py~L1101

 
         if (
             tracker.is_active_loop_rejected
-            and tracker.get_slot(REQUESTED_SLOT) == slot_name
+                and tracker.get_slot(REQUESTED_SLOT) == slot_name
         ):
             return False
 

rasa/core/actions/action.py~L1364

 
     should_fill_entity_slot = (
         mapping_type == SlotMappingType.FROM_ENTITY
-        and SlotMapping.entity_is_desired(mapping, tracker)
+            and SlotMapping.entity_is_desired(mapping, tracker)
     )
 
     should_fill_intent_slot = mapping_type == SlotMappingType.FROM_INTENT

rasa/core/actions/action.py~L1382

         trigger_mapping_condition_met = False
     elif (
         active_loops_in_mapping_conditions
-        and tracker.active_loop_name is not None
-        and (tracker.active_loop_name not in active_loops_in_mapping_conditions)
+            and tracker.active_loop_name is not None
+            and (tracker.active_loop_name not in active_loops_in_mapping_conditions)
     ):
         trigger_mapping_condition_met = False
 
     should_fill_trigger_slot = (
         mapping_type == SlotMappingType.FROM_TRIGGER_INTENT
-        and trigger_mapping_condition_met
+            and trigger_mapping_condition_met
     )
 
     value: List[Any] = []

rasa/core/actions/forms.py~L114

         for requested_slot_mapping in requested_slot_mappings:
             if (
                 not isinstance(requested_slot_mapping, dict)
-                or requested_slot_mapping.get("type") is None
+                    or requested_slot_mapping.get("type") is None
             ):
                 raise TypeError("Provided incompatible slot mapping")
 

rasa/core/actions/forms.py~L290

             current_tracker.sender_id,
             current_tracker.events_after_latest_restart()
             # Insert SlotSet event to make sure REQUESTED_SLOT belongs to active form.
-            + [SlotSet(REQUESTED_SLOT, self.get_slot_to_fill(current_tracker))]
-            # Insert form execution event so that it's clearly distinguishable which
-            # events were newly added.
-            + [ActionExecuted(self.name())]
-            + additional_events,
+                + [SlotSet(REQUESTED_SLOT, self.get_slot_to_fill(current_tracker))]
+                # Insert form execution event so that it's clearly distinguishable which
+                # events were newly added.
+                + [ActionExecuted(self.name())]
+                + additional_events,
             slots=domain.slots,
         )
 

rasa/core/actions/forms.py~L413

 
         if (
             slot_to_fill
-            and not extracted_slot_values
-            and not some_slots_were_validated
-            and not self._user_rejected_manually(validation_events)
+                and not extracted_slot_values
+                and not some_slots_were_validated
+                and not self._user_rejected_manually(validation_events)
         ):
             # reject to execute the form action
             # if some slot was requested but nothing was extracted

rasa/core/actions/forms.py~L540

         # no active_loop means that it is called during activation
         needs_validation = not tracker.active_loop or (
             tracker.latest_action_name == ACTION_LISTEN_NAME
-            and not tracker.is_active_loop_interrupted
+                and not tracker.is_active_loop_interrupted
         )
 
         if needs_validation:

rasa/core/channels/facebook.py~L45

         """Check if the users message is a recorded voice message."""
         return (
             "message" in message
-            and "attachments" in message["message"]
-            and message["message"]["attachments"][0]["type"] == "audio"
+                and "attachments" in message["message"]
+                and message["message"]["attachments"][0]["type"] == "audio"
         )
 
     @staticmethod

rasa/core/channels/facebook.py~L54

         """Check if the users message is an image."""
         return (
             "message" in message
-            and "attachments" in message["message"]
-            and message["message"]["attachments"][0]["type"] == "image"
+                and "attachments" in message["message"]
+                and message["message"]["attachments"][0]["type"] == "image"
         )
 
     @staticmethod

rasa/core/channels/facebook.py~L63

         """Check if the users message is a video."""
         return (
             "message" in message
-            and "attachments" in message["message"]
-            and message["message"]["attachments"][0]["type"] == "video"
+                and "attachments" in message["message"]
+                and message["message"]["attachments"][0]["type"] == "video"
         )
 
     @staticmethod

rasa/core/channels/facebook.py~L72

         """Check if the users message is a file."""
         return (
             "message" in message
-            and "attachments" in message["message"]
-            and message["message"]["attachments"][0]["type"] == "file"
+                and "attachments" in message["message"]
+                and message["message"]["attachments"][0]["type"] == "file"
         )
 
     @staticmethod

rasa/core/channels/facebook.py~L81

         """Check if the message is a message from the user."""
         return (
             "message" in message
-            and "text" in message["message"]
-            and not message["message"].get("is_echo")
+                and "text" in message["message"]
+                and not message["message"].get("is_echo")
         )
 
     @staticmethod

rasa/core/channels/facebook.py~L90

         """Check if the message is a quick reply message."""
         return (
             message.get("message") is not None
-            and message["message"].get("quick_reply") is not None
-            and message["message"]["quick_reply"].get("payload")
+                and message["message"].get("quick_reply") is not None
+                and message["message"]["quick_reply"].get("payload")
         )
 
     async def handle(self, payload: Dict, metadata: Optional[Dict[Text, Any]]) -> None:

rasa/core/channels/hangouts.py~L247

 
         elif (
             req.json["type"] == "REMOVED_FROM_SPACE"
-            and self.hangouts_user_added_intent_name
+                and self.hangouts_user_added_intent_name
         ):
             message = self.hangouts_user_added_intent_name
         else:

rasa/core/evaluation/marker_base.py~L342

             idx
             for idx, event in enumerate(events)
             if isinstance(event, ActionExecuted)
-            and event.action_name
-            == rasa.shared.core.constants.ACTION_SESSION_START_NAME
+                and event.action_name
+                    == rasa.shared.core.constants.ACTION_SESSION_START_NAME
         ]
         if len(session_start_indices) == 0:
             return [(events, 0)]

rasa/core/featurizers/single_state_featurizer.py~L302

         #  distinguish between entities and roles/groups right now.
         if (
             not entity_data
-            or not self.entity_tag_specs
-            or self.entity_tag_specs[0].num_tags < 2
+                or not self.entity_tag_specs
+                or self.entity_tag_specs[0].num_tags < 2
         ):
             # we cannot build a classifier with fewer than 2 classes
             return {}

rasa/core/featurizers/tracker_featurizers.py~L504

             for event in events
             if (
                 not isinstance(event, ActionExecuted)
-                or event.action_name != ACTION_UNLIKELY_INTENT_NAME
+                    or event.action_name != ACTION_UNLIKELY_INTENT_NAME
             )
         ]
 

rasa/core/featurizers/tracker_featurizers.py~L1007

                 # Only add unique example states unless `remove_duplicates` is `False`.
                 if (
                     not self.remove_duplicates
-                    or state_hash not in state_hash_to_label_set
+                        or state_hash not in state_hash_to_label_set
                 ):
                     example_states.append(states)
                     example_entities.append(entities)

rasa/core/lock_store.py~L306

     """Given an endpoint configuration, create a proper `LockStore` object."""
     if (
         endpoint_config is None
-        or endpoint_config.type is None
-        or endpoint_config.type == "in_memory"
+            or endpoint_config.type is None
+            or endpoint_config.type == "in_memory"
     ):
         # this is the default type if no lock store type is set
 

rasa/core/migrate.py~L350

 
         if (
             file_dict.get(KEY_TRAINING_DATA_FORMAT_VERSION)
-            == LATEST_TRAINING_DATA_FORMAT_VERSION
+                == LATEST_TRAINING_DATA_FORMAT_VERSION
         ):
             migrated_files.append(file)
 

rasa/core/policies/policy.py~L168

         featurizer = featurizer_func(**featurizer_config)
         if (
             isinstance(featurizer, MaxHistoryTrackerFeaturizer)
-            and POLICY_MAX_HISTORY in policy_config
-            and POLICY_MAX_HISTORY not in featurizer_config
+                and POLICY_MAX_HISTORY in policy_config
+                and POLICY_MAX_HISTORY not in featurizer_config
         ):
             featurizer.max_history = policy_config[POLICY_MAX_HISTORY]
         return featurizer

rasa/core/policies/policy.py~L244

             precomputations=precomputations,
             bilou_tagging=bilou_tagging,
             ignore_action_unlikely_intent=self.supported_data()
-            == SupportedData.ML_DATA,
+                == SupportedData.ML_DATA,
         )
 
         max_training_samples = kwargs.get("max_training_samples")

rasa/core/policies/policy.py~L287

             ignore_rule_only_turns=self.supported_data() == SupportedData.ML_DATA,
             rule_only_data=rule_only_data,
             ignore_action_unlikely_intent=self.supported_data()
-            == SupportedData.ML_DATA,
+                == SupportedData.ML_DATA,
         )[0]
 
     def _featurize_for_prediction(

rasa/core/policies/policy.py~L327

             ignore_rule_only_turns=self.supported_data() == SupportedData.ML_DATA,
             rule_only_data=rule_only_data,
             ignore_action_unlikely_intent=self.supported_data()
-            == SupportedData.ML_DATA,
+                == SupportedData.ML_DATA,
         )
 
     @abc.abstractmethod

rasa/core/policies/policy.py~L582

 
         return (
             self.probabilities == other.probabilities
-            and self.policy_name == other.policy_name
-            and self.policy_priority == other.policy_priority
-            and self.events == other.events
-            and self.optional_events == other.optional_events
-            and self.is_end_to_end_prediction == other.is_end_to_end_prediction
-            and self.is_no_user_prediction == other.is_no_user_prediction
-            and self.hide_rule_turn == other.hide_rule_turn
-            and self.action_metadata == other.action_metadata
+                and self.policy_name == other.policy_name
+                and self.policy_priority == other.policy_priority
+                and self.events == other.events
+                and self.optional_events == other.optional_events
+                and self.is_end_to_end_prediction == other.is_end_to_end_prediction
+                and self.is_no_user_prediction == other.is_no_user_prediction
+                and self.hide_rule_turn == other.hide_rule_turn
+                and self.action_metadata == other.action_metadata
             # We do not compare `diagnostic_data`, because it has no effect on the
             # action prediction.
         )

rasa/core/policies/rule_policy.py~L180

         fallback_action_name = config.get("core_fallback_action_name", None)
         if (
             fallback_action_name
-            and fallback_action_name not in domain.action_names_or_texts
+                and fallback_action_name not in domain.action_names_or_texts
         ):
             raise InvalidDomain(
                 f"The fallback action '{fallback_action_name}' which was "

rasa/core/policies/rule_policy.py~L382

                 fingerprint = rule_fingerprints.get(previous_action_name)
                 if (
                     not previous_action_name
-                    or not fingerprint
-                    or action_name == RULE_SNIPPET_ACTION_NAME
-                    or previous_action_name == RULE_SNIPPET_ACTION_NAME
+                        or not fingerprint
+                        or action_name == RULE_SNIPPET_ACTION_NAME
+                        or previous_action_name == RULE_SNIPPET_ACTION_NAME
                 ):
                     # do not check fingerprints for rule snippet action
                     # and don't raise if fingerprints are not satisfied

rasa/core/policies/rule_policy.py~L462

         predicted_action_name = None
         if (
             probabilities != self._default_predictions(domain)
-            or tracker.is_rule_tracker
+                or tracker.is_rule_tracker
         ):
             predicted_action_name = domain.action_names_or_texts[
                 np.argmax(probabilities)

rasa/core/policies/rule_policy.py~L481

         # but inside loop unhappy path there might be another action
         if (
             tracker.active_loop_name
-            and predicted_action_name != gold_action_name
-            and predicted_action_name == tracker.active_loop_name
+                and predicted_action_name != gold_action_name
+                and predicted_action_name == tracker.active_loop_name
         ):
             rasa.core.test.emulate_loop_rejection(tracker)
             predicted_action_name, prediction_source = self._predict_next_action(

rasa/core/policies/rule_policy.py~L504

 
         if prediction_source is not None and (
             prediction_source.startswith(DEFAULT_RULES)
-            or prediction_source.startswith(LOOP_RULES)
+                or prediction_source.startswith(LOOP_RULES)
         ):
             # the real gold action contradict the one in the rules in this case
             gold_action_name = predicted_action_name

rasa/core/policies/rule_policy.py~L548

             # only apply to contradicting story, not rule
             tracker.is_rule_tracker
             # only apply for prediction after unpredictable action
-            or prediction_source.count(PREVIOUS_ACTION) > 1
-            # only apply for prediction of action_listen
-            or predicted_action_name != ACTION_LISTEN_NAME
+                or prediction_source.count(PREVIOUS_ACTION) > 1
+                # only apply for prediction of action_listen
+                or predicted_action_name != ACTION_LISTEN_NAME
         ):
             return False
         for source in self.lookup[RULES]:
             # remove rule only if another action is predicted after action_listen
             if (
                 source.startswith(prediction_source[:-2])
-                and not prediction_source == source
+                    and not prediction_source == source
             ):
                 return True
         return False

rasa/core/policies/rule_policy.py~L574

         # by better typing in this class, but requires some refactoring
         if (
             not predicted_action_name
-            or not prediction_source
-            or predicted_action_name == gold_action_name
+                or not prediction_source
+                or predicted_action_name == gold_action_name
         ):
             return []
 

rasa/core/policies/rule_policy.py~L661

                     # we need to know which rules were used in ML trackers
                     if (
                         not tracker.is_rule_tracker
-                        and predicted_action_name == gold_action_name
+                            and predicted_action_name == gold_action_name
                     ):
                         rules_used_in_stories.add(prediction_source)
 

rasa/core/policies/rule_policy.py~L732

         logger.debug("Found no contradicting rules.")
         all_rules = (
             set(self._rules_sources.keys())
-            | self._default_sources()
-            | self._handling_loop_sources(domain)
+                | self._default_sources()
+                | self._handling_loop_sources(domain)
         )
         # set is not json serializable, so convert to list
         return list(all_rules - rules_used_in_stories)

rasa/core/policies/rule_policy.py~L841

                     # value should be set, therefore
                     # check whether it is the same as in the state
                     value_from_rules
-                    and value_from_rules != SHOULD_NOT_BE_SET
-                    and value_from_conversation != value_from_rules
+                        and value_from_rules != SHOULD_NOT_BE_SET
+                        and value_from_conversation != value_from_rules
                 ) or (
                     # value shouldn't be set, therefore
                     # it should be None or non existent in the state
                     value_from_rules == SHOULD_NOT_BE_SET
-                    and value_from_conversation
-                    # during training `SHOULD_NOT_BE_SET` is provided. Hence, we also
-                    # have to check for the value of the slot state
-                    and value_from_conversation != SHOULD_NOT_BE_SET
+                        and value_from_conversation
+                        # during training `SHOULD_NOT_BE_SET` is provided. Hence, we also
+                        # have to check for the value of the slot state
+                        and value_from_conversation != SHOULD_NOT_BE_SET
                 ):
                     return False
 

rasa/core/policies/rule_policy.py~L927

     ) -> Tuple[Optional[Text], Optional[Text]]:
         if (
             not tracker.latest_action_name == ACTION_LISTEN_NAME
-            or not tracker.latest_message
+                or not tracker.latest_message
         ):
             return None, None
 

rasa/core/policies/rule_policy.py~L958

         active_loop_rejected = tracker.is_active_loop_rejected
         should_predict_loop = (
             not active_loop_rejected
-            and tracker.latest_action
-            and tracker.latest_action.get(ACTION_NAME) != active_loop_name
+                and tracker.latest_action
+                and tracker.latest_action.get(ACTION_NAME) != active_loop_name
         )
         should_predict_listen = (
             not active_loop_rejected and tracker.latest_action_name == active_loop_name

rasa/core/policies/rule_policy.py~L1005

         """
         if (
             use_text_for_last_user_input
-            and not tracker.latest_action_name == ACTION_LISTEN_NAME
+                and not tracker.latest_action_name == ACTION_LISTEN_NAME
         ):
             # make text prediction only directly after user utterance
             # because we've otherwise already decided whether to use

rasa/core/policies/rule_policy.py~L1058

             # Hence, we have to take care of that.
             predicted_listen_from_general_rule = (
                 predicted_action_name == ACTION_LISTEN_NAME
-                and not get_active_loop_name(self._rule_key_to_state(best_rule_key)[-1])
+                    and not get_active_loop_name(
+                        self._rule_key_to_state(best_rule_key)[-1]
+                    )
             )
             if predicted_listen_from_general_rule:
                 if DO_NOT_PREDICT_LOOP_ACTION not in unhappy_path_conditions:

rasa/core/policies/rule_policy.py~L1199

                     # returning_from_unhappy_path is a negative condition,
                     # so `or` should be applied
                     returning_from_unhappy_path_from_text
-                    or returning_from_unhappy_path_from_intent
+                        or returning_from_unhappy_path_from_intent
                 ),
                 is_end_to_end_prediction=False,
             ),

rasa/core/policies/ted_policy.py~L760

         # the second - text, but only after user utterance and if not only e2e
         if (
             tracker.latest_action_name == ACTION_LISTEN_NAME
-            and TEXT in self.fake_features
-            and not self.only_e2e
+                and TEXT in self.fake_features
+                and not self.only_e2e
         ):
             tracker_state_features += self._featurize_for_prediction(
                 tracker,

rasa/core/policies/ted_policy.py~L796

             logger.debug(f"User text lead to '{e2e_action_name}'.")
             if (
                 np.max(confidences[1]) > self.config[E2E_CONFIDENCE_THRESHOLD]
-                # TODO maybe compare confidences is better
-                and np.max(similarities[1]) > np.max(similarities[0])
+                    # TODO maybe compare confidences is better
+                    and np.max(similarities[1]) > np.max(similarities[0])
             ):
                 logger.debug(f"TED predicted '{e2e_action_name}' based on user text.")
                 return confidences[1], True

rasa/core/policies/ted_policy.py~L854

         if 0 < ranking_length < len(confidence):
             renormalize = (
                 self.config[RENORMALIZE_CONFIDENCES]
-                and self.config[MODEL_CONFIDENCE] == SOFTMAX
+                    and self.config[MODEL_CONFIDENCE] == SOFTMAX
             )
             _, confidence = train_utils.rank_and_mask(
                 confidence, ranking_length=ranking_length, renormalize=renormalize

rasa/core/policies/ted_policy.py~L1339

         # check that there are SENTENCE features for the attribute name in data
         if (
             name in SENTENCE_FEATURES_TO_ENCODE
-            and FEATURE_TYPE_SENTENCE not in self.data_signature[name]
+                and FEATURE_TYPE_SENTENCE not in self.data_signature[name]
         ):
             return
         #  same for label_data
         if (
             name in LABEL_FEATURES_TO_ENCODE
-            and FEATURE_TYPE_SENTENCE not in self.label_signature[name]
+                and FEATURE_TYPE_SENTENCE not in self.label_signature[name]
         ):
             return
 

rasa/core/policies/ted_policy.py~L1797

 
         if (
             batch_encoded.get(ACTION_TEXT) is not None
-            and batch_encoded.get(ACTION_NAME) is not None
+                and batch_encoded.get(ACTION_NAME) is not None
         ):
             batch_action = batch_encoded.pop(ACTION_TEXT) + batch_encoded.pop(
                 ACTION_NAME

rasa/core/policies/ted_policy.py~L1809

         # same for user input
         if (
             batch_encoded.get(INTENT) is not None
-            and batch_encoded.get(TEXT) is not None
+                and batch_encoded.get(TEXT) is not None
         ):
             batch_user = batch_encoded.pop(INTENT) + batch_encoded.pop(TEXT)
         elif batch_encoded.get(TEXT) is not None:

rasa/core/policies/ted_policy.py~L2009

 
         if (
             self.config[ENTITY_RECOGNITION]
-            and text_output is not None
-            and text_sequence_lengths is not None
+                and text_output is not None
+                and text_sequence_lengths is not None
         ):
             losses.append(
                 self._batch_loss_entities(

rasa/core/policies/ted_policy.py~L2080

 
         if (
             self.config[ENTITY_RECOGNITION]
-            and text_output is not None
-            and text_sequence_lengths is not None
+                and text_output is not None
+                and text_sequence_lengths is not None
         ):
             pred_ids, confidences = self._batch_predict_entities(
                 tf_batch_data,

rasa/core/policies/unexpected_intent_policy.py~L756

         # the query intent is not the top likely intent
         if (
             query_intent_similarity < self.label_thresholds[query_intent_id]
-            and query_intent_id != highest_likely_intent_id
+                and query_intent_id != highest_likely_intent_id
         ):
             logger.debug(
                 f"Intent `{query_intent}-{query_intent_id}` unlikely to occur here."

rasa/core/processor.py~L585

 
             if (
                 reminder_event.kill_on_user_message
-                and self._has_message_after_reminder(tracker, reminder_event)
-                or not self._is_reminder_still_valid(tracker, reminder_event)
+                    and self._has_message_after_reminder(tracker, reminder_event)
+                    or not self._is_reminder_still_valid(tracker, reminder_event)
             ):
                 logger.debug(
                     f"Canceled reminder because it is outdated ({reminder_event})."

rasa/core/processor.py~L816

     def _should_handle_message(tracker: DialogueStateTracker) -> bool:
         return not tracker.is_paused() or (
             tracker.latest_message is not None
-            and tracker.latest_message.intent.get(INTENT_NAME_KEY)
-            == USER_INTENT_RESTART
+                and tracker.latest_message.intent.get(INTENT_NAME_KEY)
+                    == USER_INTENT_RESTART
         )
 
     def is_action_limit_reached(

rasa/core/processor.py~L844

 
         return (
             num_predicted_actions >= self.max_number_of_predictions
-            and should_predict_another_action
+                and should_predict_another_action
         )
 
     async def _run_prediction_loop(

rasa/core/processor.py~L1081

         time_delta_in_seconds = time.time() - user_uttered_event.timestamp
         has_expired = (
             time_delta_in_seconds / 60
-            > self.domain.session_config.session_expiration_time
+                > self.domain.session_config.session_expiration_time
         )
         if has_expired:
             logger.debug(

rasa/core/test.py~L236

         """Checks if intent, entity or action predictions don't match expected ones."""
         return (
             self.intent_predictions != self.intent_targets
-            or self._check_entity_prediction_target_mismatch()
-            or self.action_predictions != self.action_targets
+                or self._check_entity_prediction_target_mismatch()
+                or self.action_predictions != self.action_targets
         )
 
     @staticmethod

rasa/core/test.py~L285

         texts = sorted(
             set(
                 [str(e.get("text", "")) for e in self.entity_targets]
-                + [str(e.get("text", "")) for e in self.entity_predictions]
+                    + [str(e.get("text", "")) for e in self.entity_predictions]
             )
         )
 

rasa/core/test.py~L340

 
         predictions = (
             self.action_predictions
-            + self.intent_predictions
-            + aligned_entity_predictions
+                + self.intent_predictions
+                + aligned_entity_predictions
         )
         return targets, predictions
 

rasa/core/test.py~L648

     """
     if (
         isinstance(predicted_action, ActionRetrieveResponse)
-        and expected_action_name != predicted_action.name()
+            and expected_action_name != predicted_action.name()
     ):
         full_retrieval_name = predicted_action.get_full_retrieval_name(partial_tracker)
         predicted_action_name = (

rasa/core/test.py~L674

     )
     if (
         prediction.policy_name
-        and predicted_action != expected_action
-        and _form_might_have_been_rejected(
-            processor.domain, partial_tracker, predicted_action
-        )
+            and predicted_action != expected_action
+            and _form_might_have_been_rejected(
+                processor.domain, partial_tracker, predicted_action
+            )
     ):
         # Wrong action was predicted,
         # but it might be Ok if form action is rejected.

rasa/core/test.py~L767

         )
         if (
             fail_on_prediction_errors
-            and predicted_action != ACTION_UNLIKELY_INTENT_NAME
-            and predicted_action != expected_action
+                and predicted_action != ACTION_UNLIKELY_INTENT_NAME
+                and predicted_action != expected_action
         ):
             story_dump = YAMLStoryWriter().dumps(partial_tracker.as_story().story_steps)
             error_msg = (

rasa/core/test.py~L805

 ) -> bool:
     return (
         tracker.active_loop_name == predicted_action_name
-        and predicted_action_name in domain.form_names
+            and predicted_action_name in domain.form_names
     )
 
 

rasa/core/test.py~L898

         a["action"]
         for a in action_list
         if a["policy"]
-        and not rasa.core.policies.ensemble.is_not_in_training_data(a["policy"])
+            and not rasa.core.policies.ensemble.is_not_in_training_data(a["policy"])
     ]
 
     return len(in_training_data) / len(action_list) if action_list else 0

rasa/core/test.py~L924

         for event in tracker.applied_events():
             if (
                 isinstance(event, WronglyPredictedAction)
-                and event.action_name_prediction == ACTION_UNLIKELY_INTENT_NAME
+                    and event.action_name_prediction == ACTION_UNLIKELY_INTENT_NAME
             ):
                 max_severity = max(
                     max_severity,

rasa/core/test.py~L990

 
             if any(
                 isinstance(event, WronglyPredictedAction)
-                and event.action_name_prediction == ACTION_UNLIKELY_INTENT_NAME
+                    and event.action_name_prediction == ACTION_UNLIKELY_INTENT_NAME
                 for event in predicted_tracker.events
             ):
                 stories_with_warnings.append(predicted_tracker)

rasa/core/test.py~L1027

     for event in step.events:
         if (
             isinstance(event, WronglyPredictedAction)
-            and event.action_name
-            == event.action_name_prediction
-            == ACTION_UNLIKELY_INTENT_NAME
+                and event.action_name
+                    == event.action_name_prediction
+                    == ACTION_UNLIKELY_INTENT_NAME
         ):
             continue
         events.append(event)

rasa/core/training/interactive.py~L555

         if isinstance(event, ActionExecuted):
             if (
                 event.action_name == ACTION_UNLIKELY_INTENT_NAME
-                and event.confidence == 0
+                    and event.confidence == 0
             ):
                 continue
             bot_column.append(colored(str(event), "autocyan"))

rasa/core/training/interactive.py~L842

                 interactive_story_counter += 1
                 f.write(
                     "\n"
-                    + tracker.export_stories(
-                        writer=writer,
-                        should_append_stories=should_append_stories,
-                        e2e=SAVE_IN_E2E,
-                    )
+                        + tracker.export_stories(
+                            writer=writer,
+                            should_append_stories=should_append_stories,
+                            e2e=SAVE_IN_E2E,
+                        )
                 )
 
 

rasa/core/training/interactive.py~L928

             e["name"]
             for e in actions
             if e["name"] not in rasa.shared.core.constants.DEFAULT_ACTION_NAMES
-            and e["name"] not in old_domain.form_names
+                and e["name"] not in old_domain.form_names
         }
     )
 

rasa/core/training/interactive.py~L1055

     """Check if the form got rejected with the most recent action name."""
     return (
         tracker.get(ACTIVE_LOOP, {}).get(LOOP_NAME)
-        and action_name != tracker[ACTIVE_LOOP][LOOP_NAME]
-        and action_name != ACTION_LISTEN_NAME
+            and action_name != tracker[ACTIVE_LOOP][LOOP_NAME]
+            and action_name != ACTION_LISTEN_NAME
     )
 
 

rasa/core/training/interactive.py~L1064

     """Check whether the form is called again after it was rejected."""
     return (
         tracker.get(ACTIVE_LOOP, {}).get(LOOP_REJECTED)
-        and tracker.get("latest_action_name") == ACTION_LISTEN_NAME
-        and action_name == tracker.get(ACTIVE_LOOP, {}).get(LOOP_NAME)
+            and tracker.get("latest_action_name") == ACTION_LISTEN_NAME
+            and action_name == tracker.get(ACTIVE_LOOP, {}).get(LOOP_NAME)
     )
 
 

rasa/core/training/interactive.py~L1326

 def _is_same_entity_annotation(entity: Dict[Text, Any], other: Dict[Text, Any]) -> bool:
     return (
         entity["value"] == other["value"]
-        and entity["entity"] == other["entity"]
-        and entity.get("group") == other.get("group")
-        and entity.get("role") == other.get("group")
+            and entity["entity"] == other["entity"]
+            and entity.get("group") == other.get("group")
+            and entity.get("role") == other.get("group")
     )
 
 

rasa/core/training/interactive.py~L1731

         if all(
             [
                 terminaltables.width_and_alignment.visible_width(line)
-                <= monospace_wrapping_width
+                    <= monospace_wrapping_width
                 for line in lines
             ]
         ):

rasa/core/utils.py~L293

     # `lock_store` is `None` or `EndpointConfig`
     return (
         lock_store is not None
-        and isinstance(lock_store, EndpointConfig)
-        and lock_store.type != "in_memory"
+            and isinstance(lock_store, EndpointConfig)
+            and lock_store.type != "in_memory"
     )
 
 

rasa/engine/caching.py~L234

             entry
             for entry in all_entries
             if version.parse(MINIMUM_COMPATIBLE_VERSION)
-            > version.parse(entry.rasa_version)
+                > version.parse(entry.rasa_version)
         ]
 
     def _delete_incompatible_entries_from_cache(

rasa/engine/caching.py~L337

                     self._cache_location,
                     filenames_to_exclude=[self._cache_database_name],
                 )
-                + output_size
-                > self._max_cache_size
+                    + output_size
+                    > self._max_cache_size
             ):
                 self._drop_least_recently_used_item()
 

rasa/engine/recipes/default_recipe.py~L207

 
         self._use_end_to_end = (
             self._use_nlu
-            and self._use_core
-            and training_type == TrainingType.END_TO_END
+                and self._use_core
+                and training_type == TrainingType.END_TO_END
         )
 
         self._is_finetuning = is_finetuning

rasa/engine/recipes/default_recipe.py~L312

 
             if (
                 self.ComponentType.POLICY_WITHOUT_END_TO_END_SUPPORT in component.types
-                or self.ComponentType.POLICY_WITH_END_TO_END_SUPPORT in component.types
+                    or self.ComponentType.POLICY_WITH_END_TO_END_SUPPORT
+                        in component.types
             ):
                 raise InvalidConfigException(
                     f"Found policy '{component_name}' in NLU pipeline. Policies should "

rasa/engine/recipes/default_recipe.py~L464

 
         if (
             self._is_finetuning
-            and "finetuning_epoch_fraction" in cli_parameters
-            and EPOCHS in component.get_default_config()
+                and "finetuning_epoch_fraction" in cli_parameters
+                and EPOCHS in component.get_default_config()
         ):
             old_number_epochs = component_config.get(
                 EPOCHS, component.get_default_config()[EPOCHS]

rasa/engine/recipes/default_recipe.py~L866

             )
             if (
                 self.ComponentType.POLICY_WITH_END_TO_END_SUPPORT in component.types
-                and node_with_e2e_features
+                    and node_with_e2e_features
             ):
                 needs["precomputations"] = node_with_e2e_features
 

rasa/engine/recipes/default_recipe.py~L1105

 
         return (
             bool(content)
-            and missing_keys
-            == DefaultV1Recipe._get_missing_config_keys(content, training_type)
-            and auto_configured_keys
-            == DefaultV1Recipe._get_unspecified_autoconfigurable_keys(
-                content, training_type
-            )
+                and missing_keys
+                    == DefaultV1Recipe._get_missing_config_keys(content, training_type)
+                and auto_configured_keys
+                    == DefaultV1Recipe._get_unspecified_autoconfigurable_keys(
+                        content, training_type
+                    )
         )
 
     @staticmethod

rasa/engine/validation.py~L211

 
     if (
         language
-        and supported_languages is not None
-        and language not in supported_languages
+            and supported_languages is not None
+            and language not in supported_languages
     ):
         raise GraphSchemaValidationException(
             f"The component '{node.uses.__name__}' does not support the currently "

rasa/engine/validation.py~L221

 
     if (
         language
-        and not_supported_languages is not None
-        and language in not_supported_languages
+            and not_supported_languages is not None
+            and language in not_supported_languages
     ):
         raise GraphSchemaValidationException(
             f"The component '{node.uses.__name__}' does not support the currently "

rasa/engine/validation.py~L263

         type_info[param_name] = ParameterInfo(
             type_annotation=type_annotation,
             is_variable_length_keyword_arg=inspect_info.kind
-            == inspect.Parameter.VAR_KEYWORD,
+                == inspect.Parameter.VAR_KEYWORD,
             has_default=inspect_info.default != inspect.Parameter.empty,
         )
 

rasa/engine/validation.py~L334

         param_name
         for param_name, param in fn_params.items()
         if not param.has_default
-        and not param.is_variable_length_keyword_arg
-        and param_name not in keywords
+            and not param.is_variable_length_keyword_arg
+            and param_name not in keywords
     }
 
 

rasa/graph_components/validators/default_recipe_validator.py~L133

         """
         if (
             training_data.response_examples
-            and ResponseSelector not in self._component_types
+                and ResponseSelector not in self._component_types
         ):
             rasa.shared.utils.io.raise_warning(
                 f"You have defined training data with examples for training a response "

rasa/graph_components/validators/default_recipe_validator.py~L242

 
         if (
             training_data.entity_synonyms
-            and EntitySynonymMapper not in self._component_types
+                and EntitySynonymMapper not in self._component_types
         ):
             rasa.shared.utils.io.raise_warning(
                 f"You have defined synonyms in your training data, but "

rasa/graph_components/validators/default_recipe_validator.py~L357

             if issubclass(node.uses, Featurizer)
             # Featurizers are split in `train` and `process_training_data` -
             # we only need to look at the node...*[Comment body truncated]*

github-actions[bot] avatar Feb 14 '24 18:02 github-actions[bot]