|
|
@ -5,6 +5,9 @@ import sys
|
|
|
|
|
|
|
|
|
|
|
|
import astroid
|
|
|
|
import astroid
|
|
|
|
import astroid.nodes
|
|
|
|
import astroid.nodes
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Disable until pylint uses astroid 2.7
|
|
|
|
|
|
|
|
import astroid.nodes.node_classes # pylint: disable=no-name-in-module
|
|
|
|
import sphinx.util.logging
|
|
|
|
import sphinx.util.logging
|
|
|
|
|
|
|
|
|
|
|
|
_LOGGER = sphinx.util.logging.getLogger(__name__)
|
|
|
|
_LOGGER = sphinx.util.logging.getLogger(__name__)
|
|
|
@ -72,9 +75,14 @@ def resolve_qualname(node, basename):
|
|
|
|
full_basename = basename
|
|
|
|
full_basename = basename
|
|
|
|
|
|
|
|
|
|
|
|
top_level_name = re.sub(r"\(.*\)", "", basename).split(".", 1)[0]
|
|
|
|
top_level_name = re.sub(r"\(.*\)", "", basename).split(".", 1)[0]
|
|
|
|
lookup_node = (
|
|
|
|
# Disable until pylint uses astroid 2.7
|
|
|
|
node if isinstance(node, astroid.node_classes.LookupMixIn) else node.scope()
|
|
|
|
if isinstance(
|
|
|
|
)
|
|
|
|
node, astroid.nodes.node_classes.LookupMixIn # pylint: disable=no-member
|
|
|
|
|
|
|
|
):
|
|
|
|
|
|
|
|
lookup_node = node
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
lookup_node = node.scope()
|
|
|
|
|
|
|
|
|
|
|
|
assigns = lookup_node.lookup(top_level_name)[1]
|
|
|
|
assigns = lookup_node.lookup(top_level_name)[1]
|
|
|
|
|
|
|
|
|
|
|
|
for assignment in assigns:
|
|
|
|
for assignment in assigns:
|
|
|
@ -182,7 +190,7 @@ def get_assign_annotation(node):
|
|
|
|
except AttributeError:
|
|
|
|
except AttributeError:
|
|
|
|
annotation_node = node.type_annotation
|
|
|
|
annotation_node = node.type_annotation
|
|
|
|
|
|
|
|
|
|
|
|
return format_annotation(annotation_node, node)
|
|
|
|
return format_annotation(annotation_node)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def is_decorated_with_property(node):
|
|
|
|
def is_decorated_with_property(node):
|
|
|
@ -436,14 +444,8 @@ def _resolve_annotation(annotation):
|
|
|
|
return resolved
|
|
|
|
return resolved
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def format_annotation(annotation, parent):
|
|
|
|
def format_annotation(annotation):
|
|
|
|
if annotation:
|
|
|
|
if annotation:
|
|
|
|
# Workaround https://github.com/PyCQA/astroid/issues/851
|
|
|
|
|
|
|
|
if annotation.parent and not isinstance(
|
|
|
|
|
|
|
|
annotation.parent, astroid.node_classes.NodeNG
|
|
|
|
|
|
|
|
):
|
|
|
|
|
|
|
|
annotation.parent = parent
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return _resolve_annotation(annotation)
|
|
|
|
return _resolve_annotation(annotation)
|
|
|
|
|
|
|
|
|
|
|
|
return annotation
|
|
|
|
return annotation
|
|
|
@ -462,7 +464,7 @@ def _iter_args(args, annotations, defaults):
|
|
|
|
if isinstance(arg, astroid.Tuple):
|
|
|
|
if isinstance(arg, astroid.Tuple):
|
|
|
|
name = "({})".format(", ".join(x.name for x in arg.elts))
|
|
|
|
name = "({})".format(", ".join(x.name for x in arg.elts))
|
|
|
|
|
|
|
|
|
|
|
|
yield (name, format_annotation(annotation, arg.parent), default)
|
|
|
|
yield (name, format_annotation(annotation), default)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_args_info(args_node): # pylint: disable=too-many-branches,too-many-statements
|
|
|
|
def get_args_info(args_node): # pylint: disable=too-many-branches,too-many-statements
|
|
|
@ -521,11 +523,9 @@ def get_args_info(args_node): # pylint: disable=too-many-branches,too-many-stat
|
|
|
|
if args_node.vararg:
|
|
|
|
if args_node.vararg:
|
|
|
|
annotation = None
|
|
|
|
annotation = None
|
|
|
|
if args_node.varargannotation:
|
|
|
|
if args_node.varargannotation:
|
|
|
|
annotation = format_annotation(args_node.varargannotation, args_node.parent)
|
|
|
|
annotation = format_annotation(args_node.varargannotation)
|
|
|
|
elif len(annotations) > annotation_offset and annotations[annotation_offset]:
|
|
|
|
elif len(annotations) > annotation_offset and annotations[annotation_offset]:
|
|
|
|
annotation = format_annotation(
|
|
|
|
annotation = format_annotation(annotations[annotation_offset])
|
|
|
|
annotations[annotation_offset], args_node.parent
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
annotation_offset += 1
|
|
|
|
annotation_offset += 1
|
|
|
|
result.append(("*", args_node.vararg, annotation, None))
|
|
|
|
result.append(("*", args_node.vararg, annotation, None))
|
|
|
|
|
|
|
|
|
|
|
@ -553,11 +553,9 @@ def get_args_info(args_node): # pylint: disable=too-many-branches,too-many-stat
|
|
|
|
if args_node.kwarg:
|
|
|
|
if args_node.kwarg:
|
|
|
|
annotation = None
|
|
|
|
annotation = None
|
|
|
|
if args_node.kwargannotation:
|
|
|
|
if args_node.kwargannotation:
|
|
|
|
annotation = format_annotation(args_node.kwargannotation, args_node.parent)
|
|
|
|
annotation = format_annotation(args_node.kwargannotation)
|
|
|
|
elif len(annotations) > annotation_offset and annotations[annotation_offset]:
|
|
|
|
elif len(annotations) > annotation_offset and annotations[annotation_offset]:
|
|
|
|
annotation = format_annotation(
|
|
|
|
annotation = format_annotation(annotations[annotation_offset])
|
|
|
|
annotations[annotation_offset], args_node.parent
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
annotation_offset += 1
|
|
|
|
annotation_offset += 1
|
|
|
|
result.append(("**", args_node.kwarg, annotation, None))
|
|
|
|
result.append(("**", args_node.kwarg, annotation, None))
|
|
|
|
|
|
|
|
|
|
|
@ -571,9 +569,9 @@ def get_return_annotation(node):
|
|
|
|
return_annotation = None
|
|
|
|
return_annotation = None
|
|
|
|
|
|
|
|
|
|
|
|
if node.returns:
|
|
|
|
if node.returns:
|
|
|
|
return_annotation = format_annotation(node.returns, node)
|
|
|
|
return_annotation = format_annotation(node.returns)
|
|
|
|
elif node.type_comment_returns:
|
|
|
|
elif node.type_comment_returns:
|
|
|
|
return_annotation = format_annotation(node.type_comment_returns, node)
|
|
|
|
return_annotation = format_annotation(node.type_comment_returns)
|
|
|
|
|
|
|
|
|
|
|
|
return return_annotation
|
|
|
|
return return_annotation
|
|
|
|
|
|
|
|
|
|
|
|