← Back to DAGDA | Support | Source: https://github.com/ambv/static-annotations/commit/b2122e246ed524d8eaad3b64762aebd912e49ccc
Skip to content
This repository was archived by the owner on Jun 22, 2020. It is now read-only.

Commit b2122e2

Browse files
author
Lukasz Langa
committed
Extend rejected ideas with verbatim strings, future import name, and a note on thunks
1 parent 72cf2d7 commit b2122e2

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

‎pep-0563.rst‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,11 @@ This would be prohibitively expensive for highly annotated code as the
350350
frames would keep all their objects alive. That includes predominantly
351351
objects that won't ever be accessed again.
352352

353+
To be able to address class-level scope, the lambda approach would
354+
require a new kind of cell in the interpreter. This would proliferate
355+
the number of types that can appear in ``__annotations__``, as well as
356+
wouldn't be as introspectable as strings.
357+
353358
Note that in the case of nested classes, the functionality to get the
354359
effective "globals" and "locals" at definition time is provided by
355360
``typing.get_type_hints()``.
@@ -427,6 +432,42 @@ a possibility in the future, as it's conceptually compatible with
427432
existing -O behavior (dropping docstrings and assert statements). This
428433
PEP does not invalidate the idea.
429434

435+
Pass string literals in annotations verbatim to ``__annotations__``
436+
-------------------------------------------------------------------
437+
438+
This PEP originally suggested directly storing the contents of a string
439+
literal under its respective key in ``__annotations__``. This was
440+
meant to simplify support for runtime type checkers.
441+
442+
Mark Shannon pointed out this idea was flawed since it wasn't handling
443+
situations where strings are only part of a type annotation.
444+
445+
The inconsistency of it was always apparent but given that it doesn't
446+
fully prevent cases of double-wrapping strings anyway, it is not worth
447+
it.
448+
449+
Make the name of the future import more verbose
450+
-----------------------------------------------
451+
452+
Instead of requiring the following import::
453+
454+
from __future__ import annotations
455+
456+
the PEP could call the feature more explicitly, for example
457+
``string_annotations``, ``stringify_annotations``,
458+
``annotation_strings``, ``annotations_as_strings``, ``lazy_anotations``,
459+
``static_annotations``, etc.
460+
461+
The problem with those names is that they are very verbose. Each of
462+
them besides ``lazy_annotations`` would constitute the longest future
463+
feature name in Python. They are long to type and harder to remember
464+
than the single-word form.
465+
466+
There is precedence of a future import name that sounds overly generic
467+
but in practice was obvious to users as to what it does::
468+
469+
from __future__ import division
470+
430471

431472
Prior discussion
432473
================

0 commit comments

Comments
 (0)