Skip to content
This repository was archived by the owner on Mar 26, 2026. It is now read-only.

Commit 1e6efa4

Browse files
authored
fix: retrieve constructors (#181)
1 parent fa38c8c commit 1e6efa4

1 file changed

Lines changed: 36 additions & 14 deletions

File tree

docfx_yaml/extension.py

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,7 @@ def _update_friendly_package_name(path):
717717
# Check how many arguments are present in the function.
718718
arg_count = 0
719719
try:
720-
if _type in [METHOD, FUNCTION]:
720+
if _type in [METHOD, FUNCTION, CLASS]:
721721
argspec = inspect.getfullargspec(obj) # noqa
722722
type_map = {}
723723
if argspec.annotations:
@@ -773,11 +773,11 @@ def _update_friendly_package_name(path):
773773
except IndexError:
774774
pass
775775
try:
776-
lines = inspect.getdoc(obj)
777-
lines = lines.split("\n") if lines else []
776+
if len(lines) == 0:
777+
lines = inspect.getdoc(obj)
778+
lines = lines.split("\n") if lines else []
778779
except TypeError as e:
779780
print("couldn't getdoc from method, function: {}".format(e))
780-
781781
elif _type in [PROPERTY]:
782782
lines = inspect.getdoc(obj)
783783
lines = lines.split("\n") if lines else []
@@ -890,24 +890,35 @@ def _update_friendly_package_name(path):
890890
if args or arg_count > 0:
891891
variables = summary_info['variables']
892892
arg_id = []
893+
incomplete_args = []
893894
for arg in args:
894895
arg_id.append(arg['id'])
895896

896897
if arg['id'] in variables:
897898
# Retrieve argument info from extracted map of variable info
898899
arg_var = variables[arg['id']]
899-
arg['var_type'] = arg_var.get('var_type') if arg_var.get('var_type') else ''
900-
arg['description'] = arg_var.get('description') if arg_var.get('description') else ''
900+
arg['var_type'] = arg_var.get('var_type')
901+
arg['description'] = arg_var.get('description')
902+
903+
# Only add arguments with type and description.
904+
if not (arg.get('var_type') and arg.get('description')):
905+
incomplete_args.append(arg)
906+
907+
# Remove any arguments with missing type or description from the YAML.
908+
for incomplete_arg in incomplete_args:
909+
args.remove(incomplete_arg)
901910

902911
# Add any variables we might have missed from extraction.
903912
for variable in variables:
904913
if variable not in arg_id:
905-
new_arg = {
906-
"id": variable,
907-
"var_type": variables[variable].get('var_type'),
908-
"description": variables[variable].get('description')
909-
}
910-
args.append(new_arg)
914+
# Only include arguments with type and description.
915+
if variables[variable].get('var_type') and variables[variable].get('description'):
916+
new_arg = {
917+
"id": variable,
918+
"var_type": variables[variable].get('var_type'),
919+
"description": variables[variable].get('description')
920+
}
921+
args.append(new_arg)
911922

912923
datam['syntax']['parameters'] = args
913924

@@ -941,9 +952,18 @@ def process_docstring(app, _type, name, obj, options, lines):
941952
This function takes the docstring and indexes it into memory.
942953
"""
943954

955+
cls = ""
956+
module = ""
957+
944958
# Check if we already processed this docstring.
945959
if name in app.env.docfx_uid_names:
946-
return
960+
if _type != CLASS:
961+
return
962+
else:
963+
# If we run into the same docstring twice for a class it's a
964+
# constructor. Change the constructor type from CLASS to METHOD.
965+
cls, module = _get_cls_module(_type, name)
966+
_type = METHOD
947967

948968
# Register current docstring to a set.
949969
app.env.docfx_uid_names[name] = ''
@@ -952,7 +972,9 @@ def process_docstring(app, _type, name, obj, options, lines):
952972
if _type == EXCEPTION:
953973
_type = CLASS
954974

955-
cls, module = _get_cls_module(_type, name)
975+
if not cls and not module:
976+
cls, module = _get_cls_module(_type, name)
977+
956978
if not module and _type != PROPERTY:
957979
print('Unknown Type: %s' % _type)
958980
return None

0 commit comments

Comments
 (0)