Skip to content

GH-137623: Begin enforcing docstring length in Argument Clinic #137624

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 3 commits into
base: main
Choose a base branch
from

Conversation

AA-Turner
Copy link
Member

@AA-Turner AA-Turner commented Aug 11, 2025

Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

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

I think that we should check the length for all lines, not only the first one. And the limit should be 72 for functions, __new__ and __init__, and 68 for other methods.

Also, should this be an error or warning?

@@ -15,7 +15,7 @@ def __post_init__(self) -> None:
def report(self, *, warn_only: bool = False) -> str:
msg = "Warning" if warn_only else "Error"
if self.filename is not None:
msg += f" in file {self.filename!r}"
msg += f" in file '{self.filename}'"
Copy link
Member

Choose a reason for hiding this comment

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

Why?

Copy link
Member Author

Choose a reason for hiding this comment

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

On Windows, !r prints paths with \\, which is wrong. Happy to move to a different PR?

Copy link
Member

Choose a reason for hiding this comment

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

On other hand, if the filename contain special characters it will be shown in the repr format, this is why !r is often used. This is not actual in this case, when all filenames should be good, but !r is used multiple times for file names in the clinic code, so changing it only in this particular case is not reasonable. Open a separate issue for all cases.

f"Lines should be no longer than 72 characters.")
else:
if f.full_name in OVERLONG_BODY:
fail(f"Remove {f.full_name!r} from OVERLONG_BODY!\n")
Copy link
Member

Choose a reason for hiding this comment

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

Should not it be a warning?

@@ -0,0 +1,433 @@
OVERLONG_SUMMARY = frozenset((
Copy link
Member

Choose a reason for hiding this comment

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

Another possible approach is to add a decorator that will set the flood for the function. This will keep it closer to the function definition, but it will be harder to get a list of all the flagged functions.

I don't know which approach is better, I'm just showing an alternative possibility.

@@ -15,7 +15,7 @@ def __post_init__(self) -> None:
def report(self, *, warn_only: bool = False) -> str:
msg = "Warning" if warn_only else "Error"
if self.filename is not None:
msg += f" in file {self.filename!r}"
msg += f" in file '{self.filename}'"
Copy link
Member

Choose a reason for hiding this comment

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

On other hand, if the filename contain special characters it will be shown in the repr format, this is why !r is often used. This is not actual in this case, when all filenames should be good, but !r is used multiple times for file names in the clinic code, so changing it only in this particular case is not reasonable. Open a separate issue for all cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants