4242import textwrap
4343from collections import defaultdict
4444from pathlib import Path
45- from typing import Any , Dict , List , NoReturn , Optional , Set
45+ from typing import Any , Dict , List , NoReturn , Optional , Set , Tuple
4646
4747import libcst as cst
4848from helpers import format_source_code
@@ -368,9 +368,12 @@ def _update_docstring_content(self, docstring: str) -> str:
368368 desc_indent = param_indent + " " # Indentation for description lines
369369 # Update existing parameters in the docstring
370370 if update_params :
371- docstring_lines = self ._process_existing_params (
371+ docstring_lines , params_updated = self ._process_existing_params (
372372 docstring_lines , update_params , args_index , param_indent , desc_indent
373373 )
374+ # When params_updated is still not empty, it means there are new parameters that are not in the docstring
375+ # but are in the method signature
376+ new_params = {** new_params , ** params_updated }
374377 # Add new parameters to the docstring
375378 if new_params :
376379 docstring_lines = self ._add_new_params (docstring_lines , new_params , args_index , param_indent , desc_indent )
@@ -419,8 +422,10 @@ def _process_existing_params(
419422 args_index : int ,
420423 param_indent : str ,
421424 desc_indent : str ,
422- ) -> List [str ]:
425+ ) -> Tuple [ List [str ], Dict [ str , Dict [ str , str ]] ]:
423426 """Update existing parameters in the docstring."""
427+ # track the params that are updated
428+ params_updated = params_to_update .copy ()
424429 i = args_index + 1 # Start after the 'Args:' section
425430 while i < len (docstring_lines ):
426431 line = docstring_lines [i ]
@@ -436,9 +441,9 @@ def _process_existing_params(
436441 # Check if the line is a parameter line
437442 param_line = stripped_line
438443 param_name = param_line .strip ().split ()[0 ] # Extract parameter name
439- if param_name in params_to_update :
444+ if param_name in params_updated :
440445 # Get the updated parameter info
441- param_info = params_to_update [ param_name ]
446+ param_info = params_updated . pop ( param_name )
442447 # Format the new parameter docstring
443448 param_doc_lines = self ._format_param_docstring (param_name , param_info , param_indent , desc_indent )
444449 # Find the end of the current parameter's description
@@ -464,7 +469,7 @@ def _process_existing_params(
464469 i += 1
465470 else :
466471 i += 1 # Move to the next line if not a parameter line
467- return docstring_lines
472+ return docstring_lines , params_updated
468473
469474 def _add_new_params (
470475 self ,
@@ -546,6 +551,8 @@ def _check_parameters(
546551 updates = {}
547552 # Check for new and updated parameters
548553 for param_name , param_info in dataclass_params .items ():
554+ if param_name in CORE_PARAMETERS :
555+ continue
549556 if param_name not in existing_params :
550557 # New parameter
551558 updates [param_name ] = {** param_info , "status" : "new" }
@@ -761,7 +768,7 @@ def _check_and_update_parameters(
761768 "❌ Mismatch between between parameters defined in tasks methods signature in "
762769 "`./src/huggingface_hub/inference/_client.py` and parameters defined in "
763770 "`./src/huggingface_hub/inference/_generated/types.py \n "
764- "Please run `make inference_update` or `python utils/generate_task_parameters .py --update"
771+ "Please run `make inference_update` or `python utils/check_task_parameters .py --update"
765772 )
766773 exit (1 )
767774 else :
0 commit comments