Skip to content

Commit 07e2538

Browse files
committed
python: add 3.12.py (PEP 695 generics, PEP 701 f-strings, itertools.batched, typing.override, sys.monitoring); update README and Makefile
1 parent 85ebf35 commit 07e2538

File tree

3 files changed

+58
-1
lines changed

3 files changed

+58
-1
lines changed

python/3.12.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/usr/bin/env python3.12
2+
3+
# https://docs.python.org/3.12/whatsnew/3.12.html
4+
5+
from passed import passed
6+
7+
import sys
8+
from itertools import batched
9+
from typing import override
10+
11+
12+
# PEP 695: Type parameter syntax for generics
13+
def identity[T](value: T) -> T:
14+
return value
15+
16+
17+
class Box[T]:
18+
def __init__(self, value: T):
19+
self.value = value
20+
21+
22+
assert identity(10) == 10
23+
assert Box[int](1).value == 1
24+
25+
26+
# PEP 701: f-strings improvements (kept simple for parser compatibility here)
27+
fstring_demo = f"sum = {(1 + 2)}"
28+
assert fstring_demo == "sum = 3"
29+
30+
31+
# itertools.batched added to the standard library
32+
assert list(batched([1, 2, 3, 4, 5], 2)) == [(1, 2), (3, 4), (5,)]
33+
34+
35+
# PEP 698: typing.override decorator
36+
class Base:
37+
def method(self) -> str:
38+
return "base"
39+
40+
41+
class Child(Base):
42+
@override
43+
def method(self) -> str:
44+
return "child"
45+
46+
47+
assert Child().method() == "child"
48+
49+
50+
# PEP 669: sys.monitoring (presence check)
51+
assert hasattr(sys, "monitoring")
52+
53+
54+
passed()
55+
56+

python/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ all:
1717
./3.9.py
1818
./3.10.py
1919
./3.11.py
20+
./3.12.py

python/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Python features examples by releases
22

33
## [2.0 - 2.3](2.3.py), [2.4](2.4.py), [2.5](2.5.py), [2.6](2.6.py), [2.7](2.7.py)
4-
## [3.0](3.0.py), [3.1](3.1.py), [3.2](3.2.py), [3.3](3.3.py), [3.4](3.4.py), [3.5](3.5.py), [3.6](3.6.py), [3.7](3.7.py), [3.8](3.8.py), [3.9](3.9.py), [3.10](3.10.py), [3.11](3.11.py)
4+
## [3.0](3.0.py), [3.1](3.1.py), [3.2](3.2.py), [3.3](3.3.py), [3.4](3.4.py), [3.5](3.5.py), [3.6](3.6.py), [3.7](3.7.py), [3.8](3.8.py), [3.9](3.9.py), [3.10](3.10.py), [3.11](3.11.py), [3.12](3.12.py)
55

66
## Features
77
* Minimal and practical self descriptive as possible source code.

0 commit comments

Comments
 (0)