<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Sat, Jan 17, 2015 at 1:43 AM, Stefan Behnel <span dir="ltr"><<a href="mailto:stefan_ml@behnel.de" target="_blank">stefan_ml@behnel.de</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">Guido van Rossum schrieb am 16.01.2015 um 21:08:<br>
<span class="">> I don't know what to answer for Cython -- doesn't it have its own syntax<br>
> for declaring C types? Or is it now also using annotations?<br>
<br>
</span>It can, but it's optional. When I added support for it, I took care not to<br>
enable it by default, so that it wouldn't accidentally interfere with other<br>
usages of annotations.<br><br></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
The current proposal seems less generous in this regard, and the way I see<br>
it, the only gain from Cython's point of view is its very limited support<br>
for container item type declarations and function signatures of callable<br>
objects. Both are restricted to Python object types and even imply slightly<br>
different semantics than Cython (I didn't see a notion of "exact types" as<br>
opposed to "type or subtype").<br></blockquote><div> <br></div><div>Actually, while the PEP is still lacking in clarity and we're still having some discussions, type variables will most likely be "invariant" by default, which I think is the "exact types" notion you are after. There's lots of discussion in <a href="https://github.com/ambv/typehinting/issues/2">https://github.com/ambv/typehinting/issues/2</a> (you might want to read this from the end :-).<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
If there was at least a notion of "unknown types" that tools like static<br>
type checkers MUST ignore (couldn't find that in the PEP either), then<br>
Cython users could mix this with Cython's Python level type mapping through<br>
the "cython" magic module, e.g. something like "cython.struct(x=<a href="http://cython.int" target="_blank">cython.int</a>,<br>
y=cython.p_char)".<br></blockquote><div><br></div><div>Perhaps you could supply a stub for the cython module that declares everything in it as type 'Any'? That should shut the type checker up.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
OTOH, Cython could easily understand the proposed type declarations and<br>
apply runtime type checks for them to compiled Python code. Not sure if<br>
that would be considered an interesting feature, though.<br></blockquote></div><br></div><div class="gmail_extra">You should ask Cython's users what they think.<br><br>For me personally, it has taken me a long time to make peace with the idea that the static type checker runs as a separate program, like a linter, and has no effect on the runtime behavior of the program. But now that I have made that peace, I feel it's easier to make progress. I no longer feel the pressure to design a type system that can describe everything Python can do (which is impossible). It's enough to design a type system that can describe most of what most programmers do with Python most of the time (when they're not feeling too hacky). As long as there's an escape to say "don't worry about this part," such a type checker can be a very useful tool (like a linter, but much better; it can also be used in an IDE).<br><br></div><div class="gmail_extra">(And in fact there are several escape hatches. You could choose not to run the checker at all, or you could ignore some or all of its advice. Or you can leave out annotations from parts of your program. Or you can use an explicit 'Any' annotation. ('Any' is not the same as 'object'!) Or you can use a decorator or a magic comment to disable checking of code that uses annotations for other purposes.)<br></div><div class="gmail_extra"><br>-- <br><div class="gmail_signature">--Guido van Rossum (<a href="http://python.org/~guido">python.org/~guido</a>)</div>
</div></div>