Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: retrieve constructors #181

Merged
merged 1 commit into from
Feb 15, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 36 additions & 14 deletions docfx_yaml/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ def _update_friendly_package_name(path):
# Check how many arguments are present in the function.
arg_count = 0
try:
if _type in [METHOD, FUNCTION]:
if _type in [METHOD, FUNCTION, CLASS]:
argspec = inspect.getfullargspec(obj) # noqa
type_map = {}
if argspec.annotations:
Expand Down Expand Up @@ -773,11 +773,11 @@ def _update_friendly_package_name(path):
except IndexError:
pass
try:
lines = inspect.getdoc(obj)
lines = lines.split("\n") if lines else []
if len(lines) == 0:
lines = inspect.getdoc(obj)
lines = lines.split("\n") if lines else []
except TypeError as e:
print("couldn't getdoc from method, function: {}".format(e))

elif _type in [PROPERTY]:
lines = inspect.getdoc(obj)
lines = lines.split("\n") if lines else []
Expand Down Expand Up @@ -890,24 +890,35 @@ def _update_friendly_package_name(path):
if args or arg_count > 0:
variables = summary_info['variables']
arg_id = []
incomplete_args = []
for arg in args:
arg_id.append(arg['id'])

if arg['id'] in variables:
# Retrieve argument info from extracted map of variable info
arg_var = variables[arg['id']]
arg['var_type'] = arg_var.get('var_type') if arg_var.get('var_type') else ''
arg['description'] = arg_var.get('description') if arg_var.get('description') else ''
arg['var_type'] = arg_var.get('var_type')
arg['description'] = arg_var.get('description')

# Only add arguments with type and description.
if not (arg.get('var_type') and arg.get('description')):
incomplete_args.append(arg)

# Remove any arguments with missing type or description from the YAML.
for incomplete_arg in incomplete_args:
args.remove(incomplete_arg)

# Add any variables we might have missed from extraction.
for variable in variables:
if variable not in arg_id:
new_arg = {
"id": variable,
"var_type": variables[variable].get('var_type'),
"description": variables[variable].get('description')
}
args.append(new_arg)
# Only include arguments with type and description.
if variables[variable].get('var_type') and variables[variable].get('description'):
new_arg = {
"id": variable,
"var_type": variables[variable].get('var_type'),
"description": variables[variable].get('description')
}
args.append(new_arg)

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

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

cls = ""
module = ""

# Check if we already processed this docstring.
if name in app.env.docfx_uid_names:
return
if _type != CLASS:
return
else:
# If we run into the same docstring twice for a class it's a
# constructor. Change the constructor type from CLASS to METHOD.
cls, module = _get_cls_module(_type, name)
_type = METHOD

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

cls, module = _get_cls_module(_type, name)
if not cls and not module:
cls, module = _get_cls_module(_type, name)

if not module and _type != PROPERTY:
print('Unknown Type: %s' % _type)
return None
Expand Down