what is correct way of type hint a function that return only a specific set of values?
<p>I have a function that can only return <code>a</code>, <code>b</code> or <code>c</code> all of them are of type <code>T</code> but I want to make part of its signature this fact because of the special meaning they carry in the context of the function, how I do that?</p>

<p>currently I use this</p>

<pre><code>def fun(...) -&gt; "a or b or c":
    #briefly explain the meaning of a, b and c in its docstring
</code></pre>

<p>is that the correct one?</p>

<p>I know that I can do this</p>

<pre><code>def fun(...) -&gt; T:
    #briefly explain the meaning of a, b and c in its docstring
</code></pre>

<p>but as I said I want to express in the signature that the function only return those specific values</p>

<p>If all are of the same exact type just <em>add that as the return type</em>:</p>

<pre><code>def func(...) -&gt; T: # or int or whatever else
</code></pre>

<blockquote>
  <p>I want to express in the signature that the function only return those specific values</p>
</blockquote>

<p>Type hints don't specify a name or a value they just specify a <em>type</em>; a type checker tries to <em>act</em> on the <em>type</em> that's provided.</p>

<p>If you're just doing this for documentation purposes, add <code>'a or b or c</code>' to it if you want; users will understand it but type checkers <em>won't</em> and they definitely won't act on it.</p>

python python-3.x type-hinting