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

[Python APIView] docstring and annotations with *args are being mixed #8574

Open
swathipil opened this issue Jul 8, 2024 · 6 comments
Open
Assignees
Labels
APIView Priority 3 APIView Client This issue points to a problem in the data-plane of the library. Python

Comments

@swathipil
Copy link
Member

The [APIView] for the following method seems to be mixing docstring and annotations in the signature:

class InvalidContentError(ValueError):
    """Error during encoding or decoding content with a schema.

    :param str message: The message object stringified as 'message' attribute
    :keyword dict[str, str] or None details: The error details. Depending on the error, this may include
     information like: `schema_id`, `schema_definition`, `message_content`.
    :keyword error: The original exception, if any.

    :ivar str message: A stringified version of the message parameter
    :ivar dict[str, str] details: The error details. Depending on the error, this may include
     information like: `schema_id`, `schema_definition`, `message_content`.
    """

    def __init__(self, message: str, *args: Any, **kwargs: Any) -> None:

APIView:

    def __init__(
    self,
    message: str,
    *args: Any,
    *,
    error = ...
    **kwargs: Any
    ) -> None:

I would expect that the APIView method signature looks entirely like the method signature and not the docstring. Should I update this method/docstring in some way or is this is an APIView bug? Thanks!

@github-actions github-actions bot added the needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. label Jul 8, 2024
@swathipil
Copy link
Member Author

swathipil commented Jul 10, 2024

Additionally, since *args is included in the APIView, another * after that is not needed. It is implied that the arguments following * are kwargs. Expected APIView:

  def __init__(
    self,
    message: str,
    *args: Any,
    error = ...
    **kwargs: Any
    ) -> None:

@kurtzeborn kurtzeborn added APIView Client This issue points to a problem in the data-plane of the library. and removed needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. labels Jul 15, 2024
@github-project-automation github-project-automation bot moved this to 🆕 New in ApiView Jul 15, 2024
@kurtzeborn
Copy link
Member

@tjprescott, we believe this is in the Python parser. If you find that's not true, go ahead and reassign to @chidozieononiwu

@tjprescott
Copy link
Member

@swathipil yes, APIView does very purposefully pull param and type info from docstrings because it does not render the docstrings. This is certainly a parser bug.

@tjprescott
Copy link
Member

I'm not sure why only error and messages are appearing, but are you intending to use a mix of keyword and ivar?

@swathipil
Copy link
Member Author

Hi @tjprescott - Sorry for the late response! Didn't see this until just now. Yes, we're using both keywords and ivars. For example, the keyword message will also be an ivar.

@lmazuel lmazuel assigned swathipil and unassigned tjprescott Oct 8, 2024
@swathipil
Copy link
Member Author

swathipil commented Oct 8, 2024

All docstring should be using Python 3 typehints/syntax now. The Schema Registry method now looks like:

 """Error during encoding or decoding content with a schema.

    :param str message: The message object stringified as 'message' attribute
    :keyword dict[str, str] or None details: The error details. Depending on the error, this may include
     information like: `schema_id`, `schema_definition`, `message_content`.

    :ivar str message: A stringified version of the message parameter
    :ivar dict[str, str] details: The error details. Depending on the error, this may include
     information like: `schema_id`, `schema_definition`, `message_content`.
    """

    def __init__(self, message: str, *args: Any, details: Optional[Dict[str, str]] = None) -> None:

ivar with an argtype including a comma or space is still not parsed correctly.

@maririos maririos moved this from 🆕 New to 📋 Backlog in ApiView Oct 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
APIView Priority 3 APIView Client This issue points to a problem in the data-plane of the library. Python
Projects
Status: 📋 Backlog
Development

No branches or pull requests

3 participants