@@ -247,7 +247,7 @@ class SphinxDocstring(Docstring):
247
247
248
248
re_multiple_simple_type = r"""
249
249
(?:{container_type}|{type})
250
- (?:(?:\s+(?:of|or)\s+|\s*,\s*)(?:{container_type}|{type}))*
250
+ (?:(?:\s+(?:of|or)\s+|\s*,\s*|\s+\|\s+ )(?:{container_type}|{type}))*
251
251
""" .format (
252
252
type = re_type , container_type = re_simple_container_type
253
253
)
@@ -449,7 +449,7 @@ class GoogleDocstring(Docstring):
449
449
450
450
re_multiple_type = r"""
451
451
(?:{container_type}|{type}|{xref})
452
- (?:(?:\s+(?:of|or)\s+|\s*,\s*)(?:{container_type}|{type}|{xref}))*
452
+ (?:(?:\s+(?:of|or)\s+|\s*,\s*|\s+\|\s+ )(?:{container_type}|{type}|{xref}))*
453
453
""" .format (
454
454
type = re_type , xref = re_xref , container_type = re_container_type
455
455
)
@@ -728,22 +728,25 @@ class NumpyDocstring(GoogleDocstring):
728
728
re .X | re .S | re .M ,
729
729
)
730
730
731
- re_default_value = r"""((['"]\w+\s*['"])|(True)|(False)|(None))"""
731
+ re_default_value = r"""((['"]\w+\s*['"])|(\d+)|( True)|(False)|(None))"""
732
732
733
733
re_param_line = re .compile (
734
734
rf"""
735
- \s* (\*{{0,2}}\w+)(\s?(:|\n)) # identifier with potential asterisks
735
+ \s* (?P<param_name> \*{{0,2}}\w+)(\s?(:|\n)) # identifier with potential asterisks
736
736
\s*
737
- (
737
+ (?P<param_type>
738
738
(
739
739
({ GoogleDocstring .re_multiple_type } ) # default type declaration
740
740
(,\s+optional)? # optional 'optional' indication
741
741
)?
742
742
(
743
743
{{({ re_default_value } ,?\s*)+}} # set of default values
744
744
)?
745
- \n)?
746
- \s* (.*) # optional description
745
+ (?:$|\n)
746
+ )?
747
+ (
748
+ \s* (?P<param_desc>.*) # optional description
749
+ )?
747
750
""" ,
748
751
re .X | re .S ,
749
752
)
@@ -794,15 +797,26 @@ def match_param_docs(self) -> tuple[set[str], set[str]]:
794
797
continue
795
798
796
799
# check if parameter has description only
797
- re_only_desc = re .match (r"\s* (\*{0,2}\w+)\s*:?\n" , entry )
800
+ re_only_desc = re .match (r"\s*(\*{0,2}\w+)\s*:?\n\s*\w*$ " , entry )
798
801
if re_only_desc :
799
- param_name = match .group (1 )
800
- param_desc = match .group (2 )
802
+ param_name = match .group ("param_name" )
803
+ param_desc = match .group ("param_type" )
801
804
param_type = None
802
805
else :
803
- param_name = match .group (1 )
804
- param_type = match .group (3 )
805
- param_desc = match .group (4 )
806
+ param_name = match .group ("param_name" )
807
+ param_type = match .group ("param_type" )
808
+ param_desc = match .group ("param_desc" )
809
+ # The re_param_line pattern needs to match multi-line which removes the ability
810
+ # to match a single line description like 'arg : a number type.'
811
+ # We are not trying to determine whether 'a number type' is correct typing
812
+ # but we do accept it as typing as it is in the place where typing
813
+ # should be
814
+ if param_type is None and re .match (r"\s*(\*{0,2}\w+)\s*:.+$" , entry ):
815
+ param_type = param_desc
816
+ # If the description is "" but we have a type description
817
+ # we consider the description to be the type
818
+ if not param_desc and param_type :
819
+ param_desc = param_type
806
820
807
821
if param_type :
808
822
params_with_type .add (param_name )
0 commit comments