79
79
"PR09" : 'Parameter "{param_name}" description should finish with "."' ,
80
80
"PR10" : 'Parameter "{param_name}" requires a space before the colon '
81
81
"separating the parameter name and type" ,
82
- "PR11" : 'Parameter "{param_name}" is optional but not documented' ,
82
+ "PR11" : 'Parameter "{param_name}" is optional but not documented, ' "or vice versa" ,
83
83
"RT01" : "No Returns section found" ,
84
84
"RT02" : "The first line of the Returns section should contain only the "
85
85
"type, unless multiple values are being returned" ,
@@ -583,7 +583,8 @@ def validate(obj_name):
583
583
584
584
for param , kind_desc in doc .doc_all_parameters .items ():
585
585
if not param .startswith ("*" ): # Check can ignore var / kwargs
586
- if not doc .parameter_type (param ):
586
+ param_type = doc .parameter_type (param )
587
+ if not param_type :
587
588
if ":" in param :
588
589
errs .append (error ("PR10" , param_name = param .split (":" )[0 ]))
589
590
else :
@@ -593,13 +594,19 @@ def validate(obj_name):
593
594
errs .append (error ("PR05" , param_name = param ))
594
595
# skip common_type_error checks when the param type is a set of
595
596
# options
596
- if "{" in doc . parameter_type ( param ) :
597
+ if "{" in param_type :
597
598
continue
598
599
common_type_errors = [
599
600
("integer" , "int" ),
600
601
("boolean" , "bool" ),
601
602
("string" , "str" ),
602
603
]
604
+
605
+ # check that documented optional param has default in sig
606
+ if "optional" in param_type or "default" in param_type :
607
+ if param not in doc .optional_signature_parameters_names :
608
+ errs .append (error ("PR11" , param_name = param ))
609
+
603
610
for wrong_type , right_type in common_type_errors :
604
611
if wrong_type in doc .parameter_type (param ):
605
612
errs .append (
@@ -611,13 +618,14 @@ def validate(obj_name):
611
618
)
612
619
)
613
620
614
- for param in doc .optional_signature_parameters_names :
615
- type = doc .parameter_type (param )
616
- if "optional" not in type and "{" not in type and "default" not in type :
617
- errs .append (error ("PR11" , param_name = param ))
618
-
619
621
errs .extend (_check_desc (kind_desc [1 ], "PR07" , "PR08" , "PR09" , param_name = param ))
620
622
623
+ # check param with default in sig is documented as optional
624
+ for param in doc .optional_signature_parameters_names :
625
+ type = doc .parameter_type (param )
626
+ if "optional" not in type and "{" not in type and "default" not in type :
627
+ errs .append (error ("PR11" , param_name = param ))
628
+
621
629
if doc .is_function_or_method :
622
630
if not doc .returns :
623
631
if doc .method_returns_something :
0 commit comments