On Thu, Nov 25, 2021 at 3:49 PM Greg Ewing <greg.ewing@canterbury.ac.nz> wrote:
On 26/11/21 4:15 am, Stephen J. Turnbull wrote:
> My understanding is that optional,
> incremental type hints are and have always been considered the primary
> use case for annotations by the BDFL

I'm not sure that's true. The way I remember it, back when
annotations were first introduced, the BDFL didn't say that,
or at least didn't say it very clearly. It sounded more like
type hints were just one of many possible uses, and he
encouraged people to experiment. There were even discussions
about coming up with a convention to manage conflicting uses
of annotations in the same code. That wouldn't have happened
if typing were considered the only supported use.

My memory is also hazy, but I'm quite sure that *in my mind* annotations were intended as a compromise between conflicting proposals for *typing*. We didn't have agreement on the syntax or semantics, but we did know we wanted to do something with types eventually. Some folks wanted to enforce types at runtime. Others wanted to use them to generate faster code. Yet others wanted types to be checked by the compiler. The term "gradual typing" wasn't invented (or hadn't reached our community) yet, and offline static type checking wasn't something we had thought of either (I think). But it was clear that typing would have to be optional.

Fortunately the current situation is that there are few people who want to use annotations for non-typing, but there are still conflicting use cases, in particular offline static type checking on the one hand (which started with mypy and PEP 484) and some runtime use of types on the other hand (pydantic being the main example IIUC).

Tools like pydantic seem to have adopted the *notation* of PEP 484 fully, but their *interpretation* is different. This was explicitly provided for by PEP 484 (the design there carefully ensures that annotations are fully introspectable) but it wasn't anticipated to be a big use case, hence the mistaken belief at the time PEP 563 was accepted that stringifying annotations would be sufficient for the introspection use case.

So I'm in agreement with Stephen, but since he left out any mention of offline static checking, his observation isn't helping much.

--
--Guido van Rossum (python.org/~guido)