[Python-ideas] Proposal: Use mypy syntax for function annotations

Guido van Rossum guido at python.org
Mon Aug 25 04:30:35 CEST 2014


This argument over the word "static" is getting ridiculous. The meaning of
"static analysis" is perfectly well understood (just Google it) and using
Python run-time introspection for the code being analyzed is exactly what
you *don't* want in this case, for a variety of reasons. (And that includes
doing the analysis as part of the byte-code compilation that may happen at
import/load time. Once any part of the program is executing it's simply too
late for the kind of analysis we're interested in.)

People who are talking about what should happen if a decorator changes
__annotations__ are likewise missing the point. (This doesn't mean that
decorators aren't allowed to affect the signature. But the static analyzer
has to use its static powers to figure out what the decorator does, or it
has to be told, e.g. via a stub file.)

Note that I am okay with being somewhat skittish about the term "static
typing", given Python's long struggle for legitimacy in a world where
professors everywhere used to equate static typing and strong typing and
tell their impressionable students that it was the Right Way.

We should probably avoid "static typing" and use "type hinting" instead
(following TypeScript's lead I believe). But the process of looking for
violations against the hinted types before the code run is still called
static analysis.


On Sun, Aug 24, 2014 at 7:11 PM, Antoine Pitrou <antoine at python.org> wrote:

>
> Le 24/08/2014 21:30, Steven D'Aprano a écrit :
>
>
>>> 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
>>
>
> No, that's the standard definition of "static" in a certain category of
> languages such as C. Python has "static methods" and they don't happen at
> compile-time: "staticmethod" is a regular callable which is invoked at
> runtime.
>
> And there are other precedents, such as RPython which is also "statically"
> typed but... using code loaded from imported modules (in other words, I'm
> not inventing anything new here).
>
>
>  This proposal isn't just about the Python interpreter, its also about
>> static tools like linters, IDEs and editors.
>>
>
> Those so-called "static" tools are free to invoke the interpreter and use
> Python's *runtime* introspection facilities. And I'm sure some of them do.
>
> Really, it's amusing that I tried several times to explain you that
> "static" analysis didn't need to happen in an entirely separate evaluation
> context, and you still don't get it. You speak like some C programmer who
> has newly discovered Python and doesn't realize the magnitude of the
> differences between the two languages.
>
> Therefore I think the word "static" should be banned from this entire
> discussion, otherwise folks like you will keep associating irrelevant
> concepts with it.
>
> Regards
>
> Antoine.
>
>
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>



-- 
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140824/983e4e06/attachment.html>


More information about the Python-ideas mailing list