@@ -670,8 +670,8 @@ def eval_math_expression(expression: str) -> Optional[Union[float, int]]:
670
670
671
671
672
672
def eval_node (node ):
673
- if isinstance (node , ast .Num ): # <number>
674
- return node .n
673
+ if isinstance (node , ast .Constant ): # <number>
674
+ return node .value
675
675
elif isinstance (node , ast .BinOp ): # <left> <operator> <right>
676
676
return MATH_OPERATORS [type (node .op )](eval_node (node .left ), eval_node (node .right ))
677
677
elif isinstance (node , ast .UnaryOp ): # <operator> <operand> e.g., -1
@@ -931,7 +931,12 @@ def fix_docstring(obj: Any, old_doc_args: str, new_doc_args: str):
931
931
932
932
if idx == len (source ):
933
933
# Args are not defined in the docstring of this object
934
- return
934
+ obj_file = find_source_file (obj )
935
+ raise ValueError (
936
+ f"Cannot fix docstring of { obj .__name__ } in { obj_file } because no argument section was found in the docstring. "
937
+ f"The docstring should contain a section starting with 'Args:', 'Arguments:', 'Parameters:', or similar. "
938
+ f"Current docstring:\n { obj .__doc__ [:200 ]} { '...' if len (obj .__doc__ ) > 200 else '' } "
939
+ )
935
940
936
941
# Get to the line where we stop documenting arguments
937
942
indent = find_indent (source [idx ])
@@ -947,7 +952,17 @@ def fix_docstring(obj: Any, old_doc_args: str, new_doc_args: str):
947
952
948
953
if "" .join (source [start_idx :idx ])[:- 1 ] != old_doc_args :
949
954
# Args are not fully defined in the docstring of this object
950
- return
955
+ obj_file = find_source_file (obj )
956
+ actual_args_section = "" .join (source [start_idx :idx ])[:- 1 ]
957
+ raise ValueError (
958
+ f"Cannot fix docstring of { obj .__name__ } in { obj_file } because the argument section in the source code "
959
+ f"does not match the expected format. This usually happens when:\n "
960
+ f"1. The argument section is not properly indented\n "
961
+ f"2. The argument section contains unexpected formatting\n "
962
+ f"3. The docstring parsing failed to correctly identify the argument boundaries\n \n "
963
+ f"Expected argument section:\n { repr (old_doc_args )} \n \n "
964
+ f"Actual argument section found:\n { repr (actual_args_section )} \n \n "
965
+ )
951
966
952
967
obj_file = find_source_file (obj )
953
968
with open (obj_file , "r" , encoding = "utf-8" ) as f :
0 commit comments