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 keyword arguments for docstrings #389

Merged
merged 10 commits into from
Sep 6, 2024
Merged

Conversation

dandhlee
Copy link
Collaborator

@dandhlee dandhlee commented Aug 9, 2024

From inspect.getfullargspec, keyword arguments were stored as different attributes, under kwonlyargs and kwonlydefaults.

  • Added retrieval for kwonlyargs
  • Retrieve for kwonlydefaults as well, for default values stored for keyword arguments. Interestingly, defaults are stored as tuples of values but kwonlydefaults is stored as name & value KVP, so I've directly addressed this. Since dictionaries retain order, this won't mess up the order for existing defaults algorithm.
  • Adjusted spacing to remove indentation as much as possible for relevant parts

Fixes #313. See b/358448617 for context and staging to verify the fixes.

  • Tests pass - this would be updated in goldens once it's fixed.

@product-auto-label product-auto-label bot added the size: m Pull request size is medium. label Aug 9, 2024
@dandhlee dandhlee marked this pull request as ready for review August 9, 2024 06:17
@dandhlee dandhlee requested review from a team as code owners August 9, 2024 06:17
@dandhlee dandhlee requested a review from tbpg August 9, 2024 06:17
docfx_yaml/extension.py Outdated Show resolved Hide resolved

# Retrieve arguments from various source,s like `argspec.args`,
# `argspec.kwonlyargs` for positional/keyword arguments.
args_to_iterate = argspec.args
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider original_args.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

arg_map['var_type'] = type_map[arg]
args.append(arg_map)

annotations = getattr(argspec, 'annotations', [])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need tests?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Normally the test would involve updating the goldens as this function is called directly from Sphinx and can't be mocked easily.

I could refactor the logic out and add unit tests separately as a followup, and release only when the refactoring of this method is done.

Co-authored-by: Tyler Bui-Palsulich <26876514+tbpg@users.noreply.github.com>
Copy link
Collaborator Author

@dandhlee dandhlee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! Please take a look again.


# Retrieve arguments from various source,s like `argspec.args`,
# `argspec.kwonlyargs` for positional/keyword arguments.
args_to_iterate = argspec.args
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

arg_map['var_type'] = type_map[arg]
args.append(arg_map)

annotations = getattr(argspec, 'annotations', [])
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Normally the test would involve updating the goldens as this function is called directly from Sphinx and can't be mocked easily.

I could refactor the logic out and add unit tests separately as a followup, and release only when the refactoring of this method is done.

@dandhlee dandhlee requested a review from tbpg August 9, 2024 21:53
docfx_yaml/extension.py Show resolved Hide resolved
docfx_yaml/extension.py Show resolved Hide resolved
docfx_yaml/extension.py Outdated Show resolved Hide resolved
@dandhlee
Copy link
Collaborator Author

dandhlee commented Sep 6, 2024

Ran tests over several libraries locally.

Copy link

@dansaadati dansaadati left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If possible, please make sure this has golden coverage somewhere (the * arg not breaking default args that follow).

@dandhlee dandhlee merged commit bb6898e into main Sep 6, 2024
8 checks passed
@dandhlee dandhlee deleted the retrieve_args branch September 6, 2024 19:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size: m Pull request size is medium.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Optional parameters docstring not retrieved
4 participants