You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To reproduce, use the following code in ./tests/data/playground.py and run pytest.
from typing import Literal
def testLiteral() -> Literal["foo"]:
"""
Test literal.
Returns:
Literal["foo"]: Return literal string foo.
"""
return "foo"
It raises the following error: DOC203: Function `testLiteral` return type(s) in docstring not consistent with the return annotation. Return annotation types: ["Literal[\'foo\']"]; docstring return section types: [\'Literal["foo"]\']
The issue seems to stem from the fact that when the Python AST unparses code it uses single quotes by default:
Some code formatters like black replace single quotes with double, which will result in violation 203 being thrown. A temporary work around for users is continuing to use the double quotes in the return but using single quotes in the docstring, i.e.
from typing import Literal
def testLiteral() -> Literal["foo"]:
"""
Test literal.
Returns:
Literal['foo']: Return literal string foo.
"""
return "foo"
as black doesn't touch the single quotes in the docstring. But I'm not a fan of the (slight) inconsistency between docstring and return annotation 😛
The text was updated successfully, but these errors were encountered:
To reproduce, use the following code in
./tests/data/playground.py
and runpytest
.It raises the following error:
DOC203: Function `testLiteral` return type(s) in docstring not consistent with the return annotation. Return annotation types: ["Literal[\'foo\']"]; docstring return section types: [\'Literal["foo"]\']
The issue seems to stem from the fact that when the Python AST unparses code it uses single quotes by default:
Some code formatters like
black
replace single quotes with double, which will result in violation 203 being thrown. A temporary work around for users is continuing to use the double quotes in the return but using single quotes in the docstring, i.e.as
black
doesn't touch the single quotes in the docstring. But I'm not a fan of the (slight) inconsistency between docstring and return annotation 😛The text was updated successfully, but these errors were encountered: