Skip to content

Commit e05c724

Browse files
committed
fix: add uv and more info
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
1 parent ea1e512 commit e05c724

12 files changed

+185
-497
lines changed

notebooks/0 Intro.ipynb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,6 @@
243243
"\n",
244244
"| Python | Release | SPEC 0 drop | General EOL |\n",
245245
"|----------------|--------------|--------------|--------------|\n",
246-
"| ~~Python 3.8~~ | ~~Oct 2019~~ | ~~Oct 2022~~ | ~~Oct 2024~~ |\n",
247246
"| ~~Python 3.9~~ | ~~Oct 2020~~ | ~~Oct 2023~~ | ~~Oct 2025~~ |\n",
248247
"| Python 3.10 | Oct 2021 | ~~Oct 2024~~ | Oct 2026 |\n",
249248
"| Python 3.11 | Oct 2022 | ~~Oct 2025~~ | Oct 2027 |\n",

notebooks/1.3 Logging.ipynb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,10 @@
117117
"\n",
118118
"```toml\n",
119119
"[tool.pytest.ini_options]\n",
120-
"log_cli_level = \"info\"\n",
121-
"```"
120+
"log_level = \"info\"\n",
121+
"```\n",
122+
"\n",
123+
"(In pytest 9+, you can drop the `.ini_options` part!)"
122124
]
123125
},
124126
{
@@ -166,7 +168,7 @@
166168
],
167169
"metadata": {
168170
"kernelspec": {
169-
"display_name": "Python [conda env:level-up-your-python] *",
171+
"display_name": "conda-env-level-up-your-python-py",
170172
"language": "python",
171173
"name": "conda-env-level-up-your-python-py"
172174
},
@@ -180,7 +182,7 @@
180182
"name": "python",
181183
"nbconvert_exporter": "python",
182184
"pygments_lexer": "ipython3",
183-
"version": "3.10.5"
185+
"version": "3.14.3"
184186
}
185187
},
186188
"nbformat": 4,

notebooks/1.4 Debugging.ipynb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@
22
"cells": [
33
{
44
"cell_type": "markdown",
5-
"metadata": {},
5+
"metadata": {
6+
"editable": true,
7+
"slideshow": {
8+
"slide_type": ""
9+
},
10+
"tags": []
11+
},
612
"source": [
713
"# Debugging\n",
814
"\n",
@@ -116,7 +122,7 @@
116122
"cell_type": "markdown",
117123
"metadata": {},
118124
"source": [
119-
"The mini-language here is `pdb`, and is similar to `gdb` and many other debuggers. You can step forward, up, etc. You can set breakpoints, or in Python 3.7+, you can just write `breakpoint()` anywhere, and the \"current\" debugger will pick up there!"
125+
"The mini-language here is `pdb`, and is similar to `gdb` and many other debuggers. You can step forward, up, etc. You can set breakpoints, or you can just write `breakpoint()` anywhere, and the \"current\" debugger will pick up there!"
120126
]
121127
},
122128
{

notebooks/1.5 Profiling.ipynb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"\n",
1414
"## Line profiler\n",
1515
"\n",
16-
"There is a build in cProfile (one of the very, very few modules to still have the \"classic\" Python 2 naming scheme), but instead, let's use `line_profiler` and its IPython magic. Let's start with this simple file that contains a MC sampler:"
16+
"There is a build in cProfile (one of the very, very few modules to still have the \"classic\" Python 2 naming scheme; new name coming in Python 3.15), but instead, let's use `line_profiler` and its IPython magic. Let's start with this simple file that contains a MC sampler:"
1717
]
1818
},
1919
{
@@ -147,6 +147,16 @@
147147
"\n",
148148
"Please see [Fil](https://github.com/pythonspeed/filprofiler). It doesn't provide Python 3.14 wheels yet, and doesn't work with notebooks, so not included here."
149149
]
150+
},
151+
{
152+
"cell_type": "markdown",
153+
"id": "9",
154+
"metadata": {},
155+
"source": [
156+
"## Modern sampling profiling\n",
157+
"\n",
158+
"Python 3.15 will have a built-in sampling profiler, and it's great. IMO, grabbing an alpha release (with uv) is already easier than setting up any other sampling profiler."
159+
]
150160
}
151161
],
152162
"metadata": {

notebooks/2.1 Errors.ipynb

Lines changed: 87 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@
22
"cells": [
33
{
44
"cell_type": "markdown",
5-
"metadata": {},
5+
"metadata": {
6+
"editable": true,
7+
"slideshow": {
8+
"slide_type": ""
9+
},
10+
"tags": []
11+
},
612
"source": [
713
"# Errors and catching them\n",
814
"\n",
@@ -16,17 +22,30 @@
1622
{
1723
"cell_type": "code",
1824
"execution_count": null,
19-
"metadata": {},
25+
"metadata": {
26+
"editable": true,
27+
"slideshow": {
28+
"slide_type": ""
29+
},
30+
"tags": [
31+
"raises-exception"
32+
]
33+
},
2034
"outputs": [],
2135
"source": [
22-
"# Uncomment this to see an exception:\n",
23-
"# 1 / 0"
36+
"1 / 0"
2437
]
2538
},
2639
{
2740
"cell_type": "code",
2841
"execution_count": null,
29-
"metadata": {},
42+
"metadata": {
43+
"editable": true,
44+
"slideshow": {
45+
"slide_type": ""
46+
},
47+
"tags": []
48+
},
3049
"outputs": [],
3150
"source": [
3251
"try:\n",
@@ -37,31 +56,55 @@
3756
},
3857
{
3958
"cell_type": "markdown",
40-
"metadata": {},
59+
"metadata": {
60+
"editable": true,
61+
"slideshow": {
62+
"slide_type": ""
63+
},
64+
"tags": []
65+
},
4166
"source": [
4267
"Exceptions use inheritance to form a tree structure, so you can be as tight or as loose as needed in catching them. Let's see the parents of Zero Division error:"
4368
]
4469
},
4570
{
4671
"cell_type": "code",
4772
"execution_count": null,
48-
"metadata": {},
73+
"metadata": {
74+
"editable": true,
75+
"slideshow": {
76+
"slide_type": ""
77+
},
78+
"tags": []
79+
},
4980
"outputs": [],
5081
"source": [
5182
"ZeroDivisionError.__mro__"
5283
]
5384
},
5485
{
5586
"cell_type": "markdown",
56-
"metadata": {},
87+
"metadata": {
88+
"editable": true,
89+
"slideshow": {
90+
"slide_type": ""
91+
},
92+
"tags": []
93+
},
5794
"source": [
5895
"You could catch any of these instead:"
5996
]
6097
},
6198
{
6299
"cell_type": "code",
63100
"execution_count": null,
64-
"metadata": {},
101+
"metadata": {
102+
"editable": true,
103+
"slideshow": {
104+
"slide_type": ""
105+
},
106+
"tags": []
107+
},
65108
"outputs": [],
66109
"source": [
67110
"try:\n",
@@ -72,7 +115,13 @@
72115
},
73116
{
74117
"cell_type": "markdown",
75-
"metadata": {},
118+
"metadata": {
119+
"editable": true,
120+
"slideshow": {
121+
"slide_type": ""
122+
},
123+
"tags": []
124+
},
76125
"source": [
77126
"Always catch the most narrow exception you can! Never try to catch a really broad class or all exceptions, because things like running out of memory, exit signals, and more are exceptions too, and you don't want to catch those if you didn't mean to!\n",
78127
"\n",
@@ -82,7 +131,13 @@
82131
{
83132
"cell_type": "code",
84133
"execution_count": null,
85-
"metadata": {},
134+
"metadata": {
135+
"editable": true,
136+
"slideshow": {
137+
"slide_type": ""
138+
},
139+
"tags": []
140+
},
86141
"outputs": [],
87142
"source": [
88143
"class MyNewException(RuntimeError):\n",
@@ -97,15 +152,27 @@
97152
},
98153
{
99154
"cell_type": "markdown",
100-
"metadata": {},
155+
"metadata": {
156+
"editable": true,
157+
"slideshow": {
158+
"slide_type": ""
159+
},
160+
"tags": []
161+
},
101162
"source": [
102163
"There can be as many `except` blocks as you need, there's an `else` block if you want something to run only if nothing was caught, and there's also a `finally` block, which will always run, even if the exception is caught:"
103164
]
104165
},
105166
{
106167
"cell_type": "code",
107168
"execution_count": null,
108-
"metadata": {},
169+
"metadata": {
170+
"editable": true,
171+
"slideshow": {
172+
"slide_type": ""
173+
},
174+
"tags": []
175+
},
109176
"outputs": [],
110177
"source": [
111178
"try:\n",
@@ -118,7 +185,13 @@
118185
},
119186
{
120187
"cell_type": "markdown",
121-
"metadata": {},
188+
"metadata": {
189+
"editable": true,
190+
"slideshow": {
191+
"slide_type": ""
192+
},
193+
"tags": []
194+
},
122195
"source": [
123196
"Where would you want something like this? How about closing a file!\n",
124197
"\n",

notebooks/2.2 Generators.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@
298298
],
299299
"metadata": {
300300
"kernelspec": {
301-
"display_name": "Python [conda env:level-up-your-python] *",
301+
"display_name": "conda-env-level-up-your-python-py",
302302
"language": "python",
303303
"name": "conda-env-level-up-your-python-py"
304304
},
@@ -312,7 +312,7 @@
312312
"name": "python",
313313
"nbconvert_exporter": "python",
314314
"pygments_lexer": "ipython3",
315-
"version": "3.10.5"
315+
"version": "3.14.3"
316316
},
317317
"toc-autonumbering": false,
318318
"toc-showmarkdowntxt": false,

notebooks/2.3 Decorators.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@
307307
],
308308
"metadata": {
309309
"kernelspec": {
310-
"display_name": "Python [conda env:level-up-your-python] *",
310+
"display_name": "conda-env-level-up-your-python-py",
311311
"language": "python",
312312
"name": "conda-env-level-up-your-python-py"
313313
},
@@ -321,7 +321,7 @@
321321
"name": "python",
322322
"nbconvert_exporter": "python",
323323
"pygments_lexer": "ipython3",
324-
"version": "3.10.5"
324+
"version": "3.14.3"
325325
},
326326
"toc-autonumbering": false,
327327
"toc-showmarkdowntxt": false,

notebooks/2.4 Context Managers.ipynb

Lines changed: 2 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -112,65 +112,11 @@
112112
"source": [
113113
"[Pretty much everything](https://docs.python.org/3/library/contextlib.html) in the `contextlib` module that does not have the word `async` in it is worth learning. `contextlib.closing` turns an object with a `.close()` into a context manager, and `contextlib.ExitStack` lets you nest context managers without eating up massive amounts of whitespace."
114114
]
115-
},
116-
{
117-
"cell_type": "markdown",
118-
"metadata": {},
119-
"source": [
120-
"## Quick note: Async\n",
121-
"\n",
122-
"Everything we've been doing has built on itself, and we seemed to be going somewhere; the pinnacle of this direction was actually not context managers, but `async/await`. All of this feeds into `async/await`, which was formally introduced as a language component in Python 3.6. However, we did skip a necessary step; we didn't talk about generators (iterators can actually \"send\" values in, not just produce them, but there's no specific construct for doing that, like there is for consuming values in a for loop). The main reason we didn't try to reach `async` though is that I've never found a great use for it in scientific programming; it is much more intrusive than normal threading, it doesn't really \"live\" side-by-side with normal synchronous programming all that well (it's better now, though), and the libraries for it are a little young. Feel free to investigate on your own, though! I've also discussed the mechanisms behind it in detail in my blog a few years ago."
123-
]
124-
},
125-
{
126-
"cell_type": "markdown",
127-
"metadata": {},
128-
"source": [
129-
"Let's whet your appetite with a quick example, though:"
130-
]
131-
},
132-
{
133-
"cell_type": "code",
134-
"execution_count": null,
135-
"metadata": {},
136-
"outputs": [],
137-
"source": [
138-
"import asyncio\n",
139-
"\n",
140-
"\n",
141-
"# This is an \"async\" function, like a generator\n",
142-
"async def slow(t: int) -> int:\n",
143-
" print(f\"About to sleep for {t} seconds\")\n",
144-
" await asyncio.sleep(t)\n",
145-
" print(f\"Slept for {t} seconds\")\n",
146-
" return t\n",
147-
"\n",
148-
"\n",
149-
"# Gather runs its arguments in parallel when awaited on\n",
150-
"await asyncio.gather(slow(3), slow(1), slow(2))\n",
151-
"\n",
152-
"# Only works if running in an eventloop already, like IPython or with python -m asyncio\n",
153-
"# Otherwise, use: asyncio.run(...)"
154-
]
155-
},
156-
{
157-
"cell_type": "markdown",
158-
"metadata": {},
159-
"source": [
160-
"Notice _there are no locks_! We don't have to worry about printing being overleaved, because it's not running at the same time. Only the explicit \"await\" lines \"wait\" at the same time!"
161-
]
162-
},
163-
{
164-
"cell_type": "markdown",
165-
"metadata": {},
166-
"source": [
167-
"Once we start using Python 3.11 (probably early-mid 2023, based on Pyodide), an asyncio section using TaskGroups will likely be added."
168-
]
169115
}
170116
],
171117
"metadata": {
172118
"kernelspec": {
173-
"display_name": "Python [conda env:level-up-your-python] *",
119+
"display_name": "conda-env-level-up-your-python-py",
174120
"language": "python",
175121
"name": "conda-env-level-up-your-python-py"
176122
},
@@ -184,7 +130,7 @@
184130
"name": "python",
185131
"nbconvert_exporter": "python",
186132
"pygments_lexer": "ipython3",
187-
"version": "3.10.5"
133+
"version": "3.14.3"
188134
},
189135
"toc-autonumbering": false,
190136
"toc-showmarkdowntxt": false,

0 commit comments

Comments
 (0)