Skip to content

Instantly share code, notes, and snippets.

@akimboyko
Last active November 21, 2025 11:42
Show Gist options
  • Select an option

  • Save akimboyko/04a84e816a48fa846c840250da16845d to your computer and use it in GitHub Desktop.

Select an option

Save akimboyko/04a84e816a48fa846c840250da16845d to your computer and use it in GitHub Desktop.
Python 3.14 release review
def foo(x: int = 3, y: MyType = None) -> float:
pass
class MyType:
pass
foo_y_annotation = foo.__annotations__['y']
name = "ML team"
template = t"Here is a cookie for {name}"
print(type(template))
print(template)
print(str(template))
def f():
raise ExceptionGroup(
"group1",
[
LookupError(1),
ValueError(2),
ExceptionGroup(
"subgroup2",
[
OSError(3),
RecursionError(4),
SystemError(5)
]
)
]
)
try:
f()
except* LookupError, ValueError:
print("There were LookupError or ValueError")
except* OSError:
print("There were OSError")
except* RuntimeError:
print("There were RuntimeError")
except* SystemError:
print("There were SystemError")
def f():
try:
return 0
except:
return 1
finally:
return 2
# from https://facebook.github.io/zstd/
from compression import gzip
from compression import zstd
import bz2
from random import randbytes
import math
import time
from faker import Faker
data = str(math.pi).encode() * 20
# data = randbytes(4*1024**2)
fake = Faker()
data = "\n".join(fake.paragraphs(100)).encode()
start = time.time()
compressed_zstd = zstd.compress(data)
end_zstd = time.time() - start
start = time.time()
compressed_gzip = gzip.compress(data)
end_gzip = time.time() - start
start = time.time()
compressed_bz2 = bz2.compress(data)
end_bz2 = time.time() - start
ratio_zstd = len(compressed_zstd) / len(data)
ratio_gzip = len(compressed_gzip) / len(data)
ratio_bz2 = len(compressed_bz2) / len(data)
print(f"Achieved compression zstd ratio of {ratio_zstd:.04} for {len(data)} to {len(compressed_zstd)} {end_zstd:.5}")
print(f"Achieved compression gzip ratio of {ratio_gzip:.04} for {len(data)} to {len(compressed_gzip)} {end_gzip:.5}")
print(f"Achieved compression bz2 ratio of {ratio_bz2:.04} for {len(data)} to {len(compressed_bz2)} {end_bz2:.5}")

𝜋thon 3.14

𝜋thon in 3.14

Easter-egg 𝜋thon only for 3.14

PEP 649 & PEP 749: Deferred evaluation of annotations

def foo(x: int = 3, y: MyType = None) -> float:
    pass

class MyType:
    pass

foo_y_annotation = foo.__annotations__['y']

PEP 734: Multiple interpreters in the standard library

TODO

PEP 750: Template string literals

name = "ML team"
template = t"Here is a cookie for {name}"
print(template)

PEP 784: Zstandard support in the standard library

from compression import zstd
data = bytes(...)
compressed_zstd = zstd.compress(data)

Asyncio introspection capabilities

python -m asyncio ps PID
python -m asyncio pstree PID


python -m asyncio ps 12345

tid        task id              task name            coroutine stack                                    awaiter chain                                      awaiter name    awaiter id
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
1935500    0x7fc930c18050       Task-1               TaskGroup._aexit -> TaskGroup.__aexit__ -> main                                                                       0x0
1935500    0x7fc930c18230       Sundowning           TaskGroup._aexit -> TaskGroup.__aexit__ -> album   TaskGroup._aexit -> TaskGroup.__aexit__ -> main    Task-1          0x7fc930c18050
1935500    0x7fc93173fa50       TMBTE                TaskGroup._aexit -> TaskGroup.__aexit__ -> album   TaskGroup._aexit -> TaskGroup.__aexit__ -> main    Task-1          0x7fc930c18050
1935500    0x7fc93173fdf0       TNDNBTG              sleep -> play                                      TaskGroup._aexit -> TaskGroup.__aexit__ -> album   Sundowning      0x7fc930c18230
1935500    0x7fc930d32510       Levitate             sleep -> play                                      TaskGroup._aexit -> TaskGroup.__aexit__ -> album   Sundowning      0x7fc930c18230
1935500    0x7fc930d32890       DYWTYLM              sleep -> play                                      TaskGroup._aexit -> TaskGroup.__aexit__ -> album   TMBTE           0x7fc93173fa50
1935500    0x7fc93161ec30       Aqua Regia           sleep -> play         

PEP 758: Allow except and except* expressions without brackets

except* is from Python 3.10 to unpack exceptions

try:
    connect_to_server()
except TimeoutError, ConnectionRefusedError:
    print('The network has ceased to be!')

PEP 765: Control flow in finally blocks

def f():
    try:
        pass
    except:
        return 0
    finally:
        return 1
> SyntaxWarning: 'return' in a 'finally' block

Incremental garbage collection

The cycle garbage collector is now incremental. This means that maximum pause times are reduced by an order of magnitude or more for larger heaps.

There are now only two generations: young and old. When gc.collect() is not called directly, the GC is invoked a little less frequently. When invoked, it collects the young generation and an increment of the old generation, instead of collecting one or more generations.

Changed in version 3.14: generation=1 performs an increment of collection.

Other calls to gc.collect() are unchanged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment