Skip to content

Commit 76f5999

Browse files
committed
Announce the warnings module in the release notes
One bullet per entry point, each saying what it is for and what a reader has to know before reaching for it, rather than listing the names. `ignoring_warnings()` needs the reason it exists at all, which is the deduplication history a `catch_warnings()` block resets, and the cost, since that is what makes it usable where repairing the damage afterwards would not be. `asserting_no_warnings()` needs what it has over the `"error"` filter a test would otherwise use. And `deprecated_aliases()` needs both halves: the `if TYPE_CHECKING:` and `else:` shape, without which a module `__getattr__` turns every unknown name in that module into `Any`, and the shape of what it can't reach, which is the question anybody moving a whole package asks first. Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
1 parent 3d860cf commit 76f5999

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

‎RELEASE_NOTES.md‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@
1010

1111
## New Features
1212

13-
<!-- Here goes the main new features and examples or instructions on how to use them -->
13+
- A new `frequenz.core.warnings` module, with `ignoring_warnings()` to silence warnings around a piece of code. Unlike `warnings.catch_warnings()`, entering and leaving it doesn't reset the warnings deduplication history of the program, so warnings already shown are not shown again, working around [python/cpython#73858](https://github.com/python/cpython/issues/73858). It costs about the same as the standard library block, so it is also usable on a hot path, where repairing the damage afterwards would not be. `ignoring_deprecations()` is the shortcut for the most common case, a library that has to touch a symbol it deprecated itself.
14+
15+
- `frequenz.core.warnings.asserting_no_warnings()`, and its `asserting_no_deprecations()` shortcut, fail when the code in the block raises a matching warning, listing each one with the place it came from. They are meant for tests, and are a better tool than an `"error"` filter, which makes `warnings.warn()` raise inside the code under test and so changes the very behaviour the test is checking.
16+
17+
- `frequenz.core.warnings.deprecated_aliases()` builds a module `__getattr__` that warns when a symbol that moved to another module is reached through its old import path, serving the very same object so `isinstance` keeps working through both paths. The aliases are declared under `if TYPE_CHECKING:` and the `__getattr__` assigned in its `else:` branch, so type checkers see the names with their real types and never see a module `__getattr__`, which would otherwise turn every unknown name in that module into `Any`. It aliases names and not modules: a submodule that moved needs a real `__init__.py` at the old path, since the import system never consults a package's `__getattr__`, and an alias that resolves to a module raises `TypeError` rather than half working.
1418

1519
## Bug Fixes
1620

0 commit comments

Comments
 (0)