Re: Typing syntax and ecosystem, take 2

Date: Tue, 13 Apr 2021 19:55:38 -0400 From: Ned Batchelder <ned@nedbatchelder.com>
In another message, you alluded to PEP 649 being a solution to run-time type checking. Maybe I'm misunderstanding something: type annotations never do type checking at runtime. As I understand it, PEP 649 is about avoiding the overhead of evaluating the type expression itself, not about checking the types of values.
Yes, and I see that as a problem. Here are two versions of code V1 # Apocalypse may occur if foo is not <complicated-type> foo = "coconut" V2 # Apocalypse may occur if foo is not <complicated-type> foo : <complicated-type> = "coconut" To the Python interpreter both have the same semantics and runtime behaviour. But V2 has type annotations, which are effectively syntactically constrained comments within individual statements. As code they do absolutely nothing. However, the performance hit from just being present is so great that talented programmers are working hard to make the Python interpreter ... ignore them more efficiently. -- cheers, Hugh Fisher
participants (1)
-
Hugh Fisher