@@ -123,7 +123,7 @@ def unparse(node: ast.AST) -> List[Node]:
123123 if node .value is Ellipsis :
124124 return [addnodes .desc_sig_punctuation ('' , "..." )]
125125 else :
126- return [nodes .Text (node .value )]
126+ return [nodes .Text (repr ( node .value ) )]
127127 elif isinstance (node , ast .Expr ):
128128 return unparse (node .value )
129129 elif isinstance (node , ast .Index ):
@@ -149,6 +149,12 @@ def unparse(node: ast.AST) -> List[Node]:
149149 result .append (addnodes .desc_sig_punctuation ('' , '[' ))
150150 result .extend (unparse (node .slice ))
151151 result .append (addnodes .desc_sig_punctuation ('' , ']' ))
152+
153+ # Wrap the Text nodes inside brackets by literal node if the subscript is a Literal
154+ if result [0 ] in ('Literal' , 'typing.Literal' ):
155+ for i , subnode in enumerate (result [1 :], start = 1 ):
156+ if isinstance (subnode , nodes .Text ):
157+ result [i ] = nodes .literal ('' , '' , subnode )
152158 return result
153159 elif isinstance (node , ast .Tuple ):
154160 if node .elts :
@@ -179,7 +185,9 @@ def unparse(node: ast.AST) -> List[Node]:
179185 tree = ast_parse (annotation )
180186 result = unparse (tree )
181187 for i , node in enumerate (result ):
182- if isinstance (node , nodes .Text ) and node .strip ():
188+ if isinstance (node , nodes .literal ):
189+ result [i ] = node [0 ]
190+ elif isinstance (node , nodes .Text ) and node .strip ():
183191 result [i ] = type_to_xref (str (node ), env )
184192 return result
185193 except SyntaxError :
0 commit comments