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

Try to use type hints #48

Open
Zeroto521 opened this issue May 20, 2020 · 1 comment
Open

Try to use type hints #48

Zeroto521 opened this issue May 20, 2020 · 1 comment
Assignees

Comments

@Zeroto521
Copy link

Zeroto521 commented May 20, 2020

Since Python3.5 supports for type hints.
It could be better than writing docstring at sometimes.

Such as follow example.
We can learn from code a lot directly rather than docstring.

Before

def get(url, qsargs=None, timeout=5.0):
    """Send an HTTP GET request.

    :param url: URL for the new request.
    :type url: str
    :param qsargs: Converted to query string arguments.
    :type qsargs: dict
    :param timeout: In seconds.
    :rtype: mymodule.Response
    """
    return request('get', url, qsargs=qsargs, timeout=timeout)

Later

from typing import Dict, Optional

def get(url: str, qsargs: Optional[Dict] = None, timeout: float = 5.0) -> mymodule.Response:
    """Send an HTTP GET request.

    :param url: URL for the new request.
    :param qsargs: Converted to query string arguments.
    :param timeout: In seconds.
    """
    return request('get', url, qsargs=qsargs, timeout=timeout)
@Zeroto521 Zeroto521 changed the title type hints Try to use type hint May 20, 2020
@Zeroto521 Zeroto521 changed the title Try to use type hint Try to use type hints May 20, 2020
@amontalenti
Copy link
Owner

Love this suggestion! Thanks @Zeroto521.

This is also related to #45 which I opened a couple weeks ago, and to PR #4 (which has been open way too long, I realize).

I also recently discovered myst-parser (as I tweeted here) which seems like it provides a Markdown-ish way to provide docstrings and have them still be compatible with Sphinx. The question of how & whether to mix standard reST, Markdown, typing, and sphinx is definitely a question of style and deserves good coverage here!

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

No branches or pull requests

2 participants