# If the annotation is from the typing module, it could be a "bracketed"
# type, in which case we want to recurse to its types as well. Otherwise
# just get its name.
- elif annotation.__module__ == 'typing':
+ elif hasattr(annotation, '__module__') and annotation.__module__ == 'typing':
if sys.version_info >= (3, 7):
name = annotation._name
elif annotation is typing.Any:
else:
return 'typing.' + name
+ # Things like (float, int) instead of Tuple[float, int] or using np.array
+ # instead of np.ndarray. Ignore with a warning.
+ elif not isinstance(annotation, type):
+ logging.warning("invalid annotation %s in %s, ignoring", annotation, '.'.join(referrer_path))
+ return None
+
# Otherwise it's a plain type. Turn it into a link.
return make_name_link(state, referrer_path, map_name_prefix(state, extract_type(annotation)))
third: str = 'hello') -> <a href="inspect_annotations.Foo.html" class="m-doc">Foo</a></span>
</dt>
<dd>An annotated function</dd>
+ <dt>
+ <span class="m-doc-wrap-bumper">def <a href="#annotation_func_instead_of_type" class="m-doc-self" id="annotation_func_instead_of_type">annotation_func_instead_of_type</a>(</span><span class="m-doc-wrap">a)</span>
+ </dt>
+ <dd>Annotation with a function instead of a type, ignored</dd>
+ <dt>
+ <span class="m-doc-wrap-bumper">def <a href="#annotation_tuple_instead_of_tuple" class="m-doc-self" id="annotation_tuple_instead_of_tuple">annotation_tuple_instead_of_tuple</a>(</span><span class="m-doc-wrap">a)</span>
+ </dt>
+ <dd>Annotation with a tuple instead of Tuple, ignored</dd>
<dt>
<span class="m-doc-wrap-bumper">def <a href="#args_kwargs" class="m-doc-self" id="args_kwargs">args_kwargs</a>(</span><span class="m-doc-wrap">a, b, *args, **kwargs)</span>
</dt>
"""Partially annotated function"""
pass
+def annotation_tuple_instead_of_tuple(a: (float, int)):
+ """Annotation with a tuple instead of Tuple, ignored"""
+
+def annotation_func_instead_of_type(a: open):
+ """Annotation with a function instead of a type, ignored"""
+
# Only possible with native code now, https://www.python.org/dev/peps/pep-0570/
#def positionals_only(positional_only, /, positional_kw):
#"""Function with explicitly delimited positional args"""