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

✨ Add PEP 604 style type hint support #218

Merged
merged 10 commits into from
Feb 8, 2022

Conversation

s-weigand
Copy link
Contributor

Currently, PEP 604 style type hints are not supported, because everything after the pipe character (|) gets removed.

E.g. this function

from __future__ import annotations


def function(
    arg1: int,
    arg2: list[str] | dict[str, int] | Thing,
    kwarg1: int = 1
) -> Generator[tuple[str, str]]:

    yield ("abc", "def")

would generate the following docstring

    """[summary]

    :param arg1: [description]
    :type arg1: int
    :param arg2: [description]
    :type arg2: list[str]
    :param kwarg1: [description], defaults to 1
    :type kwarg1: int, optional
    :yield: [description]
    :rtype: Generator[tuple[str, str]]
    """

So one has to manually check and add them back.

Copy link
Owner

@NilsJPWerner NilsJPWerner 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 for the PR! The code looks good except for two test suggestions.

src/test/integration/python_test_files/file_7.py Outdated Show resolved Hide resolved
src/test/parse/tokenize_definition.spec.ts Show resolved Hide resolved
@s-weigand s-weigand force-pushed the PEP-604-typehint-support branch from 67f2c2c to 584b585 Compare February 8, 2022 08:17
@NilsJPWerner NilsJPWerner merged commit 5f2a22e into NilsJPWerner:master Feb 8, 2022
@s-weigand s-weigand deleted the PEP-604-typehint-support branch February 8, 2022 20:19
shaperilio pushed a commit to shaperilio/autoDocstring that referenced this pull request Feb 11, 2022
NilsJPWerner added a commit that referenced this pull request Feb 16, 2022
* master: (29 commits)
  Merge publish and test workflows
  Handle nested square brackets in type hints (#185)
  Improve changelog format and add publish release action
  Only run publish workflow after successful test workflow
  Bump version to 0.6.1
  Remove one-line-sphinx-notypes and update changelog
  Add example documentation of docstring formats (#224)
  Rename oneline-rst to one-line-sphinx
  Bump version to 0.6.0
  Fixes #212: Parse Literal type hints in function definition (#223)
  Add debug log statements
  Update all dependencies (#222)
  Add more notypes docstring templates (#221)
  Fixes #94: Switch square brackets in placeholder to underscores (#220)
  Avoid extra newlines in templates (#203)
  Add oneline-rst docstring to menu and readme so its accessible (#195)
  Add PEP 604 style type hint support (#218)
  Fix yield underline in numpy template (#216)
  Update READEME
  Switch to github actions (#214)
  ...
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