Hello! This is my first time on these forums, though I’ve lurked for a long time.
I understand that PEP 585 lets us type hint the standard collection objects, like
list[str], starting in 3.9 by default and optionally in 3.7 and 3.8 with
__future__. This is great! I’d been looking forward to this feature for a while.
I’m kind of confused about how it works in practice, though. This code:
from __future__ import annotations x: list[str] = ["a", "b"]
works today, as expected, in my various Python envs (one in 3.7.4 and one in some version of 3.8). But it didn’t prior to October 5th, when 3.9 was released.
How did this happen? How did the interpreter know that a future version of Python had been released, or that this code should somehow start working? What is it within
__future__ that made this start working on October 5th?
I looked at the following places online:
- The CPython source code:
https://github.com/python/cpython/blob/3.7/Lib/__future__.py(sorry, Discourse only lets me put two links in a post?)
- This blog post by Simeon Visser
- PEPs 563 and 585
- This StackOverflow rant-question
but wasn’t able to find a satisfactory answer. I apologize if this is a stupid question, and hope that I’ve expressed myself clearly, but please let me know if I haven’t.