Skip to content

Commit b20e04a

Browse files
lpozoclaudebzaczynskirealpython-bot
authored
Sample code for: Python 3.15 Preview: Sentinel Values (#823)
* Sample code for: Python 3.15 Preview: Sentinel Values * TR updates, first round Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * Apply DR/LE findings from new skills Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * Print the enum's repr() in example_006 to match the tutorial Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com> Co-authored-by: Bartosz Zaczyński <bartosz@realpython.com> Co-authored-by: Real Python Bot <42617967+realpython-bot@users.noreply.github.com>
1 parent fd59c3b commit b20e04a

37 files changed

Lines changed: 325 additions & 0 deletions
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Python 3.15 Preview: Sentinel Values
2+
3+
This folder provides the code examples for the Real Python tutorial [Python 3.15 Preview: Sentinel Values](https://realpython.com/python315-sentinel-values/)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
UNSET = sentinel("UNSET")
2+
INHERIT = sentinel("INHERITED") # Name doesn't match the variable
3+
4+
5+
class Config:
6+
AUTO = sentinel("Config.AUTO")
7+
# Some code here...
8+
NO_LIMIT = sentinel("NO_LIMIT") # Forgot the qualified name
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
print("Hello, World!".find("z"))
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import configparser
2+
import inspect
3+
import typing
4+
import unittest.mock
5+
6+
print(configparser._UNSET)
7+
print(inspect.Parameter.empty)
8+
print(typing.NoDefault)
9+
print(unittest.mock.DEFAULT)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import pickle
2+
from copy import deepcopy
3+
4+
_MISSING = object()
5+
print(_MISSING)
6+
print(type(_MISSING))
7+
print(deepcopy(_MISSING) is _MISSING)
8+
print(pickle.loads(pickle.dumps(_MISSING)) is _MISSING)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
grades = {"Jane": 90, "John": None}
2+
print(grades.get("John") is grades.get("Linda"))
3+
print("Pythonista!".find("z"))
4+
print("Pythonista!"["Pythonista!".find("z")])
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from copy import deepcopy
2+
3+
4+
class _MissingType:
5+
def __repr__(self):
6+
return "MISSING"
7+
8+
9+
MISSING = _MissingType()
10+
print(MISSING)
11+
print(deepcopy(MISSING) is MISSING)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import enum
2+
3+
4+
class MissingType(enum.Enum):
5+
MISSING = "MISSING"
6+
7+
8+
print(repr(MissingType.MISSING))
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
MISSING = sentinel("MISSING")
2+
print(MISSING)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
UNSET = sentinel("UNSET", repr="<unset>")
2+
print(UNSET)

0 commit comments

Comments
 (0)