How to determine function parameter type in python?
<p>For example I have a poorly documented library. I have an object from it and I want to know what are the types of the arguments certain method accepts.</p>

<p>In IPython I can run</p>

<pre><code>In [28]: tdb.getData?
Signature: tdb.getData(time, point_coords, sinterp=0, tinterp=0, data_set='isotropic1024coarse', getFunction='getVelocity', make_modulo=False)
Docstring: &lt;no docstring&gt;
File:      ~/.local/lib/python3.5/site-packages/pyJHTDB/libJHTDB.py
Type:      method
</code></pre>

<p>but it does not give me the types of the arguments. I don't know exactly what is the type of <code>point_coords</code>.</p>

<p>Usually, functions in Python accept arguments of any type, so you cannot define what type it expects.</p>

<p>Still, the function probably does make some implicit assumptions about the received object.</p>

<p>Take this function for example:</p>

<pre><code>def is_long(x):
    return len(x) &gt; 1000
</code></pre>

<p>What type of argument <code>x</code> does this function accept? Any type, as long as it has length defined.</p>

<p>So, it can take a string, or a list, or a dict, or any custom object you create, as long as it implements <code>__len__</code>. But it won't take an integer.</p>

<pre><code>is_long('abcd')  # ok
is_long([1, 2, 3, 4])  # ok
is_long(11)  # not ok
</code></pre>

<p><strong>To answer the question:</strong> How can you tell what assumtions the function makes?</p>

<ul>
<li>read the documentation</li>
<li>read the doc string (try <code>help(funcname)</code>)</li>
<li>guess: Pass any argument to it and see how it fails. If it fails with <em>AttributeError: X instance has no attribute 'get_value'</em>, it expects something with <code>get_value</code>.</li>
</ul>

python types