Skip to content

Commit d589704

Browse files
committed
python: 3.13.py – (TypeIs, ReadOnly, deprecated)
1 parent 07e2538 commit d589704

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

python/3.13.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env python3.13
2+
3+
# https://docs.python.org/3.13/whatsnew/3.13.html
4+
5+
from passed import passed
6+
7+
import typing as _typing
8+
from warnings import deprecated, catch_warnings, simplefilter
9+
from typing import TypeIs, ReadOnly, TypedDict
10+
11+
12+
# PEP 742: typing.TypeIs for intuitive type narrowing
13+
def is_str(value: object) -> TypeIs[str]:
14+
return isinstance(value, str)
15+
16+
17+
unknown: object = "hello"
18+
if is_str(unknown):
19+
assert unknown.upper() == "HELLO"
20+
21+
22+
# PEP 705: typing.ReadOnly for immutable fields in TypedDict
23+
class Config(TypedDict):
24+
env: ReadOnly[str]
25+
26+
27+
cfg: Config = {"env": "production"}
28+
assert cfg["env"] == "production"
29+
30+
31+
# PEP 702: deprecation decorator – pick from typing or warnings; fallback to no-op
32+
@deprecated("use 'new_api' instead")
33+
def old_api() -> int:
34+
return 1
35+
36+
37+
passed()

python/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ all:
1818
./3.10.py
1919
./3.11.py
2020
./3.12.py
21+
./3.13.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), [3.12](3.12.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), [3.13](3.13.py)
55

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

0 commit comments

Comments
 (0)