<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On 4 September 2016 at 13:30, Mark Shannon <span dir="ltr"><<a href="mailto:mark@hotpy.org" target="_blank">mark@hotpy.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">It would be a real shame if PEP 526 mandates against checkers doing as good as job as possible. Forcing all uses of a variable to have the same type is a major and, IMO crippling, limitation.<br>
<br>
E.g.<br>
def foo(x:Optional[int])->int:<br>
  if x is None:<br>
    return -1<br>
  return x + 1<br>
<br>
If the type of the *variable* 'x' is Optional[int] then 'return x + 1' doesn't type check. If the type of the *parameter* 'x' is Optional[int] then a checker can readily verify the above code.<br></blockquote></div><br></div><div class="gmail_extra">Mark,<br><br>First, in addition to the quote from my previous e-mail, I would like to show another quote from PEP 526<br>"This PEP does not require type checkers to change their type checking
rules. It merely provides a more readable syntax to replace type
comments"<br><br></div><div class="gmail_extra">Second, almost exactly your example has been added to PEP 484:<br><br><pre class="">class Reason(Enum):
timeout = 1
error = 2
def process(response: Union[str, Reason] = '') -> str:
if response is Reason.timeout:
return 'TIMEOUT'
elif response is Reason.error:
return 'ERROR'
else:
# response can be only str, all other possible values exhausted
return 'PROCESSED: ' + response</pre></div><div class="gmail_extra">I think mypy either already supports this or will support very soon (and the same for Optional)<br><br></div><div class="gmail_extra">--<br></div><div class="gmail_extra">Ivan<br><br></div></div>