On Sat, Aug 23, 2014 at 07:00:54PM -0400, Antoine Pitrou wrote:
Le 23/08/2014 13:25, Steven D'Aprano a écrit :
It's not a new use. A type class is a class, and calling it is just instantiating that class. There's nothing new here. If you think that's a bit "meta", it's no different than e.g. higher-order functions.
There's no instantiation during *static* analysis, because the code hasn't run yet.
In your idea of "static analysis", it hasn't. Because you think it should involve some kind of separate syntax analysis tool that has nothing to do with regular Python.
That's not "my" idea of static analysis, that is the standard definition of "static" as happening at compile-time. If it happens at runtime, it's not static.
But Python is powerful enough to let you do that using normal introspection of modules.
This proposal isn't just about the Python interpreter, its also about static tools like linters, IDEs and editors.
And it's *exactly* how we are exposing function annotations (and also docstrings, etc.): using runtime-accessible introspection information which is gathered by importing modules and therefore actually *executing* toplevel module code. Not merely compiling it.
Correct, the annotations will be available at runtime as well as compile-time. But tools like linters and editors will rely on static analysis, not dynamic run-time checks, and that's Guido's intention. Here's his initial post: https://mail.python.org/pipermail/python-ideas/2014-August/028618.html -- Steven