anentropic / python-waterloo

A cli tool to convert type annotations found in 'Google-style' docstrings into mypy py2 type comments (and from there into py3 type annotations).
2 stars 1 forks source link

Handle missing "Args" section if "Returns" is given #16

Closed anentropic closed 4 years ago

anentropic commented 4 years ago

This case currently gives:

  File "waterloo/refactor/annotations.py", line 144, in m_add_type_comment
    if not signature.arg_types.is_fully_typed:
AttributeError: 'NoneType' object has no attribute 'is_fully_typed'

If "Args" is not given but ALLOW_UNTYPED_ARGS =True then we should still annotate this as:
(...) -> <return type>

Thinking about it more, this case is likely to occur in situation where func takes no args. In which case we should happily annotate it as () -> <return type>, regardless of ALLOW_UNTYPED_ARGS setting.

To do that we need to inspect the function signature, which so far we haven't done.

Actually we should validate the annotation names against the signature in all cases!

If names don't match, or annotations are missing names from the signature then we should treat as is_fully_typed=False