8000 Merge branch 'master' into python-variables · realpython/materials@a703c7f · GitHub
[go: up one dir, main page]

Skip to content

Commit a703c7f

Browse files
authored
Merge branch 'master' into python-variables
2 parents d716ae6 + 66d67b3 commit a703c7f

40 files changed

+754
-1
lines changed

python-313/README.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Note that for testing the free-threading and JIT features, you'll need to build
1212

1313
You can learn more about Python 3.13's new features in the following Real Python tutorials:
1414

15-
<!-- - [Python 3.13: Cool New Features for You to Try](https://realpython.com/python313-new-features/) -->
15+
- [Python 3.13: Cool New Features for You to Try](https://realpython.com/python313-new-features/)
1616
- [Python 3.13 Preview: Free Threading and a JIT Compiler](https://realpython.com/python313-free-threading-jit/)
1717
- [Python 3.13 Preview: A Modern REPL](https://realpython.com/python313-repl)
1818

@@ -30,11 +30,28 @@ The following examples are used to demonstrate different features of the new REP
3030
- [`multiline_editing.py`](repl/multiline_editing.py)
3131
- [`power_factory.py](repl/power_factory.py)
3232
- [`guessing_game.py](repl/guessing_game.py)
33+
- [`roll_dice.py`](repl/roll_dice.py)
34+
35+
### Error messages
36+
37+
Run the scripts in the `errors/` folder to see different error messages produced by Python 3.13.
3338

3439
### Free-Threading and JIT
3540

3641
You need to enable a few build options to try out the free-threading and JIT features in Python 3.13. You can find more information in the dedicated [README file](free-threading-jit/README.md).
3742

43+
## Static typing
44+
45+
Run the scripts in the `typing/` folder to try out the new static typing features.
46+
47+
## Other features
48+
49+
The following scripts illustrate other new features in Python 3.13:
50+
51+
- [`replace.py`](replace.py): Use `copy.replace()` to update immutable data structures.
52+
- [`paths.py`](paths.py) and [`music/`](music/): Glob patterns are more consistent.
53+
- [`docstrings.py`](docstrings.py): Common leading whitespace in docstrings is stripped.
54+
3855
## Authors
3956

4057
- **Bartosz Zaczyński**, E-mail: [bartosz@realpython.com](bartosz@realpython.com)

python-313/docstrings.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import dataclasses
2+
3+
4+
@dataclasses.dataclass
5+
class Person:
6+
"""Model a person with a name, location, and Python version."""
7+
8+
name: str
9+
place: str
10+
version: str
11+
12+
13+
print(Person.__doc__)
14+
15+
print(len(dataclasses.replace.__doc__))
16+
print(dataclasses.replace.__doc__)

python-313/errors/inverse.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
def inverse(number):
2+
return 1 / number
3+
4+
5+
print(inverse(0))

python-313/errors/kwarg_suggest.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
numbers = [2, 0, 2, 4, 1, 0, 0, 1]
2+
3+
# print(sorted(numbers, reversed=True))
4+
print(sorted(numbers, reverse=True))

python-313/errors/random.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import random
2+
3+
num_faces = 6
4+
5+
print("Hit enter to roll die (q to quit, number for # of faces) ")
6+
while True:
7+
roll = input()
8+
if roll.lower().startswith("q"):
9+
break
10+
if roll.isnumeric():
11+
num_faces = int(roll)
12+
13+
result = random.randint(1, num_faces)
14+
print(f"Rolling a d{num_faces:<2d} - {result:2d}")

python-313/music/opera/flower_duet.txt

Whitespace-only changes.

python-313/music/opera/habanera.txt

Whitespace-only changes.

python-313/music/opera/nabucco.txt

Whitespace-only changes.

python-313/music/rap/bedlam_13-13.txt

Whitespace-only changes.

python-313/music/rap/fight_the_power.txt

Whitespace-only changes.

0 commit comments

Comments
 (0)
0