Skip to content

Add flake8 comma rule #8535

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

TomeHirata
Copy link
Collaborator

I've seen inconsistent comma usage among contributors, so adding flake8-comma rule for consistency. I'm open to not having this rule if we want to keep flexibility.

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR integrates the flake8-commas rule to enforce consistent use of trailing commas in multi-line structures and function calls across the codebase.

  • Add "COM" to the select list in pyproject.toml to enable flake8-commas.
  • Introduce missing trailing commas in multi-line test fixtures and function calls.
  • Apply the same formatting update to production code under dspy/, ensuring consistency.

Reviewed Changes

Copilot reviewed 79 out of 79 changed files in this pull request and generated no comments.

File Description
pyproject.toml Enable flake8-commas by adding "COM" to the select.
tests/** Added trailing commas to multi-line tuple/list/dict literals and function arguments in tests.
dspy/** Added trailing commas to multi-line function calls and data structures in production code.

Copy link
Collaborator

@chenmoneygithub chenmoneygithub left a comment

Choose a reason for hiding this comment

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

ohh I would not introduce this rule, for example code like this:

        system_user_messages = self.format(  # returns a list of dicts with the keys "role" and "content"
            signature=signature, demos=demos, inputs=inputs,
        )

is against the official python rule PEP8: https://peps.python.org/pep-0008/#when-to-use-trailing-commas, which says it should be broken down into 3 lines if a trailing comma is used.

@TomeHirata
Copy link
Collaborator Author

TomeHirata commented Jul 18, 2025

Thank you Chen, for flagging this. I read the pep8 rule again, and it seems the following example actually does not violate the rule

system_user_messages = self.format( 
    signature=signature, demos=demos, inputs=inputs,
)

The rule states, "it does not make sense to have a trailing comma on the same line as the closing delimiter", therefore this would be a violation while it does not appear in this PR.

system_user_messages = self.format(signature=signature, demos=demos, inputs=inputs,)

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.

2 participants