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

[pydoclint] Add support for Sphinx-style docstrings in the pydoclint rules. #13286

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# DOC201
def foo(num: int) -> str:
"""
Do something

:param num: A number
:type num: int
"""
return 'test'


# OK
def foo(num: int) -> str:
"""
Do something

:param num: A number
:type num: int
:return: A string
:rtype: str
"""
return 'test'


class Bar:

# OK
def foo(self) -> str:
"""
Do something

:param num: A number
:type num: int
:return: A string
:rtype: str
"""
return 'test'


# DOC201
def bar(self) -> str:
"""
Do something

:param num: A number
:type num: int
"""
return 'test'


# OK
@property
def baz(self) -> str:
"""
Do something

:param num: A number
:type num: int
"""
return 'test'
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# OK
def foo(num: int) -> str:
"""
Do something

:param num: A number
:type num: int
"""
print('test')


# DOC202
def foo(num: int) -> str:
"""
Do something

:param num: A number
:type num: int
:return: A string
:rtype: str
"""
print('test')


class Bar:

# DOC202
def foo(self) -> str:
"""
Do something

:param num: A number
:type num: int
:return: A string
:rtype: str
"""
print('test')


# OK
def bar(self) -> str:
"""
Do something

:param num: A number
:type num: int
"""
print('test')
126 changes: 126 additions & 0 deletions crates/ruff_linter/resources/test/fixtures/pydoclint/DOC402_sphinx.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
# DOC402
def foo(num: int) -> str:
"""
Do something

:param num: A number
:type num: int
"""
yield 'test'


# OK
def foo(num: int) -> str:
"""
Do something

:param num: A number
:type num: int
:yield: A string
:rtype: str
"""
yield 'test'


class Bar:

# OK
def foo(self) -> str:
"""
Do something

:param num: A number
:type num: int
:yield: A string
:rtype: str
"""
yield 'test'


# DOC402
def bar(self) -> str:
"""
Do something

:param num: A number
:type num: int
"""
yield 'test'


import typing


# OK
def foo() -> typing.Generator[None, None, None]:
"""
Do something
"""
yield None


# OK
def foo() -> typing.Generator[None, None, None]:
"""
Do something
"""
yield


# DOC402
def foo() -> typing.Generator[int | None, None, None]:
"""
Do something
"""
yield None
yield 1


# DOC402
def foo() -> typing.Generator[int, None, None]:
"""
Do something
"""
yield None


# OK
def foo():
"""
Do something
"""
yield None


# OK
def foo():
"""
Do something
"""
yield


# DOC402
def foo():
"""
Do something
"""
yield None
yield 1


# DOC402
def foo():
"""
Do something
"""
yield 1
yield


# DOC402
def bar() -> typing.Iterator[int | None]:
"""
Do something
"""
yield
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# OK
def foo(num: int) -> str:
"""
Do something

:param num: A number
:type num: int
"""
print('test')


# DOC403
def foo(num: int) -> str:
"""
Do something

:param num: A number
:type num: int
:yield: A string
:rtype: str
"""
print('test')


class Bar:

# DOC403
def foo(self) -> str:
"""
Do something

:param num: A number
:type num: int
:yield: A string
:rtype: str
"""
print('test')


# OK
def bar(self) -> str:
"""
Do something

:param num: A number
:type num: int
"""
print('test')


import typing


# OK
def foo() -> typing.Generator[None, None, None]:
"""
Do something

:yield: When X.
"""
yield None


# OK
def foo() -> typing.Generator[None, None, None]:
"""
Do something

:yield: When X.
"""
yield


# OK
def foo():
"""
Do something

:yield: When X.
"""
yield None


# OK
def foo():
"""
Do something

:yield: When X.
"""
yield
Loading
Loading