Skip to content

Small fixes for utils/check_docstrings.py #38915

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

manueldeprada
Copy link
Contributor

  1. fix ast deprecations for python 3.14 by replacing:
    1. node.n by node.value (deprecation notice)
    2. ast.Num by ast.Constant (deprecation notice)
  2. When --fix_and_overwrite is passed but fixing fails, exit with a detailed exception instead of failing silently.

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@manueldeprada manueldeprada removed the request for review from ydshieh June 19, 2025 15:19
…d use `ast.Constant`

More verbose exceptions in `fix_docstring` on docstring formatting issues.
@ydshieh
Copy link
Collaborator

ydshieh commented Jun 20, 2025

Hi @manueldeprada Thanks a lot!

This part is old and I am not the author. I think it makes sense but just have one question.

Looks like our current code is passing this modified check.

@@ -947,7 +948,17 @@ def fix_docstring(obj: Any, old_doc_args: str, new_doc_args: str):

if "".join(source[start_idx:idx])[:-1] != old_doc_args:
# Args are not fully defined in the docstring of this object
return
obj_file = find_source_file(obj)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Logically it looks good. But I have a bit hard time to understand why we might have this situation.

In match_docstring_with_signature, we have

old_doc_arg = "\n".join(obj_doc_lines[start_idx:idx])

and here old_doc_args is the original content of obj.

If you happen to know why we might have this situation "".join(source[start_idx:idx])[:-1] != old_doc_args (and even better if you have an example) , that would be very nice 🙏

Copy link
Collaborator

Choose a reason for hiding this comment

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

But it's not because of you PR confusing me, the block is already there , just return silently.

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.

3 participants