title: Python: How to write typing.overload decorator for bool arguments by value
body: <p>The example code of what I am trying to ask is below.<br />
  None of the examples on the internet try to overload argument value as such.<br />
  One of the argument is a bool value and I want to overload a method based on the bool value rather than the usual, argument type.</p>
  <pre class="lang-py prettyprint-override"><code>from typing import overload, Union
  
  @overload
  def myfunc(arg: bool = True)-&gt; str: ...
  
  @overload
  def myfunc(arg: bool = False) -&gt; int: ...
  
  def myfunc(arg: bool) -&gt; Union[int, str]:
    if arg:
      return &quot;something&quot;
    else:
      return 0
  </code></pre>
  <p>Is the overloading code in the above example code correct ?<br />
  Can you give an example/blog/source that mentions this kind of overloading, since I couldn't find anything in Python docs and <a href="https://www.python.org/dev/peps/pep-0484/" rel="nofollow noreferrer">pep-484</a></p>
  <p>I found one probable way of doing it is with <code>typing.Literal</code> as used in <a href="https://docs.python.org/3/library/typing.html#typing.Literal" rel="nofollow noreferrer">latest python docs (since python v3.8)</a></p>
  <pre class="lang-py prettyprint-override"><code>from typing import overload, Union, Literal
  
  @overload
  def myfunc(arg: Literal[True]) -&gt; str: ...
  
  @overload
  def myfunc(arg: Literal[False]) -&gt; int: ...
  
  def myfunc(arg: bool) -&gt; Union[int, str]:
    if arg:
      return &quot;something&quot;
    else:
      return 0
  </code></pre>
  <p>But I cannot move to python 3.8 just yet as I am working on production code that is still on python 3.6, soon upgrading to 3.7 at best.<br />
  Hence I am still looking for answers on how to achieve this in python 3.6</p>