<p dir="ltr">Maybe the PEP should just say it's for "annotating variables", and it would mention "primarily for the purpose of types"?</p>
<p dir="ltr">--<br>
Ryan<br>
[ERROR]: Your autotools build scripts are 200 lines longer than your program. Something’s wrong.<br>
<a href="http://kirbyfan64.github.io/">http://kirbyfan64.github.io/</a></p>
<div class="gmail_quote">On Sep 5, 2016 10:27 AM, "Mark Shannon" <<a href="mailto:mark@hotpy.org">mark@hotpy.org</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
PEP 526 states that "This PEP aims at adding syntax to Python for annotating the types of variables" and Guido seems quite insistent that the declarations are for the types of variables.<br>
<br>
However, I get the impression that most (all) of the authors and proponents of PEP 526 are quite keen to emphasise that the PEP in no way limits type checkers from doing what they want.<br>
<br>
This is rather contradictory. The behaviour of a typechecker is defined by the typesystem that it implements. Whether a type annotation determines the type of a variable or an expression alters changes what typesystems are feasible. So, stating that annotations define the type of variables *does* limit what a typechecker can or cannot do.<br>
<br>
Unless of course, others may have a different idea of what the "type of a variable" means.<br>
To me, it means it means that for all assignments `var = expr`<br>
the type of `expr` must be a subtype of the variable,<br>
and for all uses of var, the type of the use is the same as the type of the variable.<br>
<br>
In this example:<br>
<br>
  Â  def bar()->Optional[int]: ...<br>
<br>
  Â  def foo()->int:<br>
  Â  Â  Â  x:Optional[int] = bar()<br>
  Â  Â  Â  if x is None:<br>
  Â  Â  Â  Â  Â  return -1<br>
  Â  Â  Â  return x<br>
<br>
According to PEP 526 the annotation `x:Optional[int]`<br>
means that the *variable* `x` has the type `Optional[int]`.<br>
So what is the type of `x` in `return x`?<br>
If it is `Optional[int]`, then a type checker is obliged to reject this code. If it is `int` then what does "type of a variable" actually mean,<br>
and why aren't the other uses of `x` int as well?<br>
<br>
Cheers,<br>
Mark.<br>
______________________________<wbr>_________________<br>
Python-Dev mailing list<br>
<a href="mailto:Python-Dev@python.org" target="_blank">Python-Dev@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-dev" rel="noreferrer" target="_blank">https://mail.python.org/mailma<wbr>n/listinfo/python-dev</a><br>
Unsubscribe: <a href="https://mail.python.org/mailman/options/python-dev/rymg19%40gmail.com" rel="noreferrer" target="_blank">https://mail.python.org/mailma<wbr>n/options/python-dev/rymg19%<wbr>40gmail.com</a><br>
</blockquote></div>