Commit dfb0e36
authored
fix(ndb): use the single-argument generator.throw() signature (#18159)
Fixes #18158
## Summary
`_TaskletFuture._advance_tasklet` throws exceptions into the wrapped
generator using the three-argument form of `generator.throw()`,
[deprecated in Python
3.12](https://docs.python.org/3/reference/expressions.html#generator.throw):
```python
if error:
traceback = error.__traceback__
yielded = self.generator.throw(type(error), error, traceback)
```
Every exception that crosses a tasklet boundary emits a
`DeprecationWarning`. This library's own unit suite raises **70
warnings** today; with this change it raises **36**, so 34 of them came
from this single line.
Today that is only noise, but the Python docs say the old signature "may
be removed in a future version". `noxfile.py` already lists `3.15` in
`ALL_INTERPRETERS`, so it is worth landing before that removal makes
every tasklet-boundary exception raise `TypeError` instead of
propagating.
## Changes
The single-argument form reads the traceback off the exception itself,
so the local becomes redundant:
```python
if error:
yielded = self.generator.throw(error)
```
Also adds a regression test asserting both halves of the contract: the
exception still arrives with its `__traceback__` intact, and no
`DeprecationWarning` is emitted. I verified the test fails against the
old line and passes against the new one, so it genuinely guards the
behaviour rather than just tracking it.
## Verification
- `pytest tests/unit` — 1833 passed, 1 skipped (1832 before, plus the
new test); warnings drop from 70 to 36
- `ruff format --check` and `flake8 google tests` — clean
- Reproduced the original warning with only `google-cloud-ndb` and the
standard library; see #18158 for the standalone snippet1 parent 88b10ac commit dfb0e36
2 files changed
Lines changed: 35 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
314 | 314 | | |
315 | 315 | | |
316 | 316 | | |
317 | | - | |
318 | | - | |
| 317 | + | |
319 | 318 | | |
320 | 319 | | |
321 | 320 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| |||
363 | 364 | | |
364 | 365 | | |
365 | 366 | | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
366 | 400 | | |
367 | 401 | | |
368 | 402 | | |
| |||
0 commit comments