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

Hack to special case *args and *kwargs in args/parameter lists #27

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

peterjc
Copy link
Owner

@peterjc peterjc commented Apr 2, 2020

This might solve #18, but at the cost of hiding some true misuse of italics or bold within the same docstring. Might be worthwhile all the same?

(This is a bit of a surface level hack - A more precise fix would need deeper integration into the docutils internals)

Copy link

@sobolevn sobolevn left a comment

Choose a reason for hiding this comment

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

Looks like a valid hack 😄

@peterjc
Copy link
Owner Author

peterjc commented Apr 3, 2020

Looks like GitHub didn't run... curious. We ought to run this on a large test set before including this on a release.

@peterjc
Copy link
Owner Author

peterjc commented Apr 3, 2020

Using pyquil (previously tested with this package), the changes on this pull request make no difference:

$ git checkout v2.19.0
$ flake8 --select RST --rst-roles ref,py:class,py:func --rst-directives versionadded pyquil/
pyquil/gates.py:0:1: RST902 Failed to parse __all__ entry.
pyquil/simulation/matrices.py:0:1: RST902 Failed to parse __all__ entry.
pyquil/simulation/tools.py:177:1: RST301 Unexpected indentation.
pyquil/simulation/tools.py:178:1: RST201 Block quote ends without a blank line; unexpected unindent.
pyquil/simulation/tests/test_numpy.py:276:1: RST213 Inline emphasis start-string without end-string.
pyquil/simulation/tests/test_numpy.py:280:1: RST213 Inline emphasis start-string without end-string.
pyquil/api/_quantum_computer.py:928:1: RST303 Unknown directive type "deprecated".
pyquil/experiment/_program.py:52:1: RST214 Inline literal start-string without end-string.
pyquil/experiment/_program.py:52:1: RST214 Inline literal start-string without end-string

Interesting case in https://github.com/rigetti/pyquil/blob/v2.19.0/pyquil/simulation/tests/test_numpy.py#L273 which has one naughty *args in the free text (which deserves a warning and can be fixed), but in the arg list has *matrices (which the hack does not allow for).

def kron(*matrices: np.ndarray) -> np.ndarray:
    """Computes the kronecker product of a sequence of matrices.
    A *args version of lambda args: functools.reduce(np.kron, args).
    Args:
        *matrices: The matrices and controls to combine with the kronecker
            product.
    Returns:
        The resulting matrix.
    """
    ....

Could potentially inspect the function definition to decide which starred variable names to check for and thus ignore *matrices here.

@peterjc
Copy link
Owner Author

peterjc commented Apr 3, 2020

Similar in astropy, plenty of examples where the variable names are not *args and **kwargs although some cases are class level parameter documentation (so would have to look ahead to the __init__ to see the expected parameter names). Perhaps any variable name should be accepted (simpler solution).

@peterjc
Copy link
Owner Author

peterjc commented Dec 22, 2023

This needs a little refactoring now... rebasing.

@peterjc
Copy link
Owner Author

peterjc commented Dec 22, 2023

CodeClimate is rightly critical of the style of this fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants