I have numpydoc-style docstrings:
def foobar(filename, copy, dtype, iterable, shape, files):
"""
foobar is 42.
Parameters
----------
filename : str
copy : bool
dtype : data-type
iterable : iterable object
shape : int or tuple of int
files : list of str
Returns
-------
foobarfoo : int
"""
pass
Is it possible to check if the docstring-types can possibly be correct?
(side question: Can numpy return/print the function signatures it discovered?)
For example, I would expect the following to fail:
def foobar():
"""
Returns
-------
blub : int
"""
return "foo"
or
def foobar(a, b):
"""
Parameters
----------
a : number
b : number
Returns
-------
blub : int
"""
if a > b:
return "foo"
return 42
def foobar(a, b):
"""
Parameters
----------
a : str
b : int
Returns
-------
blub : int
"""
return a * b
No, mypy understands the official Python's typing notation only. See the mypy docs. And this fine, we don't need many alternative ways to type annotate, as
There should be one-- and preferably only one --obvious way to do it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With