Closed GeeTransit closed 3 months ago
Hello,
I really appreciate the work put into this extension. It's very easy to set up and to customize.
Currently, if one has a type annotation with Literal, the strings inside are treated as if they were forward references, rather than constant strings.
Literal
Given this function:
def func(arg: Literal['one', 'two', 'three']) -> str: return arg
The generated documentation is this:
func(arg: Literal[one, two, three]) → str
Rather than what would be expected:
func(arg: Literal['one', 'two', 'three']) → str
I changed astroid_utils._resolve_annotation to check if the subscript value is Literal and if so, return .as_string() for constants such as strings and bytes. I also added a few tests and a news fragment.
astroid_utils._resolve_annotation
.as_string()
The test failure has been addressed in main already.
main
Hello,
I really appreciate the work put into this extension. It's very easy to set up and to customize.
Currently, if one has a type annotation with
Literal
, the strings inside are treated as if they were forward references, rather than constant strings.Given this function:
The generated documentation is this:
Rather than what would be expected:
I changed
astroid_utils._resolve_annotation
to check if the subscript value isLiteral
and if so, return.as_string()
for constants such as strings and bytes. I also added a few tests and a news fragment.