42 lines
1.7 KiB
Diff
42 lines
1.7 KiB
Diff
From f236cd03e4853fd8b07a307e334c5110a78c1335 Mon Sep 17 00:00:00 2001
|
|
From: Eric Wieser <wieser.eric@gmail.com>
|
|
Date: Mon, 27 Apr 2020 14:44:37 +0100
|
|
Subject: [PATCH] Do not emit type arguments twice
|
|
|
|
Fixes gh-7567
|
|
---
|
|
sphinx/util/inspect.py | 9 +++++++--
|
|
1 file changed, 7 insertions(+), 2 deletions(-)
|
|
|
|
diff --git a/sphinx/util/inspect.py b/sphinx/util/inspect.py
|
|
index 20af75628..4977af07f 100644
|
|
--- a/sphinx/util/inspect.py
|
|
+++ b/sphinx/util/inspect.py
|
|
@@ -505,8 +505,13 @@ class Signature:
|
|
qualname = self.format_annotation(annotation.__origin__) # ex. Union
|
|
elif hasattr(annotation, '__qualname__'):
|
|
qualname = '%s.%s' % (module, annotation.__qualname__)
|
|
+ elif hasattr(annotation, '__origin__'):
|
|
+ # instantiated generic provided by a user
|
|
+ qualname = self.format_annotation(annotation.__origin__)
|
|
else:
|
|
- qualname = repr(annotation)
|
|
+ # we weren't able to extract the base type, appending arguments would
|
|
+ # only make them appear twice
|
|
+ return repr(annotation)
|
|
|
|
if getattr(annotation, '__args__', None):
|
|
if qualname == 'Union':
|
|
@@ -519,7 +524,7 @@ class Signature:
|
|
args = ', '.join(self.format_annotation(a) for a in annotation.__args__[:-1])
|
|
returns = self.format_annotation(annotation.__args__[-1])
|
|
return '%s[[%s], %s]' % (qualname, args, returns)
|
|
- elif annotation._special:
|
|
+ elif getattr(annotation, '_special', False):
|
|
return qualname
|
|
else:
|
|
args = ', '.join(self.format_annotation(a) for a in annotation.__args__)
|
|
--
|
|
2.26.2
|
|
|