return type of round ()
<p>I have the following piece of code:</p>

<pre><code>a_round = round (3.5)   # First use of a_round
a_round = 4.5   # Incompatible types, since a_round is regarded as an int
</code></pre>

<p>It turns out that the return value of round () is regarded as an int.
That this is so, I conclude because at the second statement, mypy complains:</p>

<pre><code>Incompatible types in assignment (expression has type "float",variable has type "int")
</code></pre>

<p>I am using Python 3.5, so it should be a float. What am I missing. Should I somehow hint mypy about the Python version? How exactly?</p>

<p>It depends on your implementation:</p>

<pre><code>&gt;&gt;&gt; round(3.5)
4
&gt;&gt;&gt; type(round(3.5))
&lt;class 'int'&gt;
&gt;&gt;&gt; round(3.5,1)
3.5
&gt;&gt;&gt; type(round(3.5,1))
&lt;class 'float'&gt;
</code></pre>

<p>Of course it is trivial to create a float in all cases:</p>

<pre><code>&gt;&gt;&gt; float(round(3.5))
4.0
&gt;&gt;&gt; type(float(round(3.5)))
&lt;class 'float'&gt;
</code></pre>

python mypy