What's the type hint for "can be converted to" mean?
<p>Let's say I want to accept anything I can call <code>int()</code> on, or anything I can call <code>str()</code> on. How do I do that with the new type hints ?</p>

<p>Annotating with <code>typing.SupportsInt</code> doesn't work, as mypy will warn against passing a string.</p>

<p>You can't, not with type hinting. Type hinting can't say anything about the <em>contents</em> of a string, only that it must <em>be</em> a string.</p>

<p>Note that <em>everything</em> in Python can be converted to a string (as <code>__repr__</code> is always available); so for 'can be converted to a string' can be handled by <code>typing.Any</code>.</p>

<p>For <code>int()</code>, you can only specify specific hooks and types again; you can specify you'll accept objects that have a <a href="https://docs.python.org/3/reference/datamodel.html#object.__int__" rel="nofollow"><code>__int__()</code></a>  method, but if you also accept strings, you can't specify what is <em>in</em> that string.</p>

<p>So:</p>

<pre><code>AcceptableToInt = Union[SupportsInt, str, bytes, bytearray]
</code></pre>

<p>would let you check on what types <code>int()</code> accepts, but not if they'll throw a <code>ValueError</code> exception when you actually try.</p>

python type-hinting