Skip to content

Conversation

@leandrodamascena
Copy link
Contributor

Issue Link (REQUIRED)

Fixes #304

Summary

Changes

This PR enables the following rule categories in our Ruff configuration:

  • A: Flake8-builtins - Checks for Python built-in names being used as variables/parameters
  • B: Flake8-bugbear - Detects common bugs and design problems

A: Flake8-builtins Rules

These rules prevent shadowing of built-in names like id, list, dict, input, etc. Shadowing built-ins can lead to:

  1. Confusing code that's difficult to understand and maintain
  2. Subtle bugs where the built-in function is unexpectedly unavailable
  3. Decreased code readability and maintainability

B: Flake8-bugbear Rules

Bugbear rules detect a wide range of common Python issues:

  1. Logical errors that may not cause syntax errors but lead to runtime bugs
  2. Anti-patterns that make code more error-prone or difficult to maintain
  3. Potentially dangerous code practices (like mutable default arguments)
  4. Loop control variable overwriting and other subtle logic issues

User experience

No changes in use experience

Checklist

If your change doesn't seem to apply, please leave them unchecked.

  • I have performed a self-review of this change
  • Changes have been tested
  • [] Changes are documented
  • I have linked this PR to an existing issue (required)
Is this a breaking change?

RFC issue number:

Checklist:

  • Migration process documented
  • Implement warnings (if it can live side by side)

Acknowledgment

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

Copy link
Contributor Author

@leandrodamascena leandrodamascena left a comment

Choose a reason for hiding this comment

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

Hey @brnaba-aws I just left some comments explaining what I'm changing.
Thanks

else:
if not isinstance(options.client, Anthropic):
raise ValueError("If streaming is disabled, the provided client must be an Anthropic client")
elif not isinstance(options.client, Anthropic):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Simplifying logic.

elif not isinstance(options.client, Anthropic):
raise ValueError("If streaming is disabled, the provided client must be an Anthropic client")
self.client = options.client
elif self.streaming:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Simplifying logic.

) -> dict:
"""Build the conversation command with all necessary configurations."""
input = {
json_input = {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Avoiding variables names that shadow built-in python functions.

async def _handle_streaming(
self,
input: dict,
payload_input: dict,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Avoiding parameters names that shadow built-in python functions.

self,
streaming: bool,
input: dict,
payload_input: dict,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Avoiding parameters names that shadow built-in python functions.

except Exception as error:
Logger.error(f"Error processing request with agent {agent.name}:{str(error)}")
raise f"Error processing request with agent {agent.name}:{str(error)}"
raise f"Error processing request with agent {agent.name}:{str(error)}" from error
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Exceptions should propagate the original error for complete stack trace.

f"{user_msg.role}:{user_msg.content[0].get('text','')}\n"
f"{asst_msg.role}:{asst_msg.content[0].get('text','')}\n"
for user_msg, asst_msg in zip(agents_history[::2], agents_history[1::2])
for user_msg, asst_msg in zip(agents_history[::2], agents_history[1::2], strict=True)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adding strict parameter to make sure zip function will unpack expected values OR will raise ValueError if not.

session_id: str,
classifier_result: ClassifierResult,
additional_params: dict[str, str] = {},
additional_params: dict[str, str] | None = None,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should not add mutable parameters in the method signature. Moving the check to inside the function.

session_id: str,
additional_params: dict[str, str] = {},
stream_response: bool | None = False) -> AgentResponse:
async def route_request(self, user_input: str, user_id: str, session_id: str, additional_params: dict[str, str] | None = None, stream_response: bool | None = False) -> AgentResponse:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should not add mutable parameters in the method signature. Moving the check to inside the function.


properties = {}
for param_name, param in sig.parameters.items():
for param_name, _param in sig.parameters.items():
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Variables is not being used, so, add _ to make it clear.

brnaba-aws pushed a commit that referenced this pull request Jun 2, 2025
@brnaba-aws
Copy link
Contributor

Closing as this has been ported manually due to conflict being too complex.

@brnaba-aws brnaba-aws closed this Jun 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enable rules A & B in Ruff

2 participants