ado, I am really excited for #Python 3.12 for three reasons.
First reason - No more ugly
TypeVar
declarations.Old generic type:
from typing import Generic, TypeVar<br></br><br></br>_T_co = TypeVar("_T_co", covariant=True, bound=str)<br></br><br></br>class ClassA(Generic[_T_co]):<br></br> def method1(self) -> _T_co:<br></br> ...<br></br>
New generic:
class ClassA[T: str]:<br></br> def method1(self) -> T:<br></br> ...<br></br>
Second reason: 🚀 Gotta go fast. From the abstract
Comprehensions are currently compiled as nested functions, which provides isolation of the comprehension’s iteration variable, but is inefficient at runtime. This PEP proposes to inline list, dictionary, and set comprehensions into the code where they are defined, and provide the expected isolation by pushing/popping clashing locals on the stack.
Last: F Strings will support some common use cases that broke interpolation in the past, like
f'{ myDict['myKey'] }'
andf"{'n'.join(a)}"
Full notes: https://www.python.org/downloads/release/python-3120b3/
Add comment