diff --git a/CHANGELOG.md b/CHANGELOG.md index c9f8382b..4e0886fc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,13 +28,15 @@ You can find our backwards-compatibility policy [here](https://github.com/hynek/ [#647](https://github.com/hynek/structlog/pull/647) - ## Fixed - `structlog.traceback.ExceptionDictTransformer` now correctly handles missing exceptions. [#657](https://github.com/hynek/structlog/pull/657) +- Instantiating `structlog.dev.ConsoleRenderer` does not mutate the passed *styles* dict anymore. + + [#658](https://github.com/hynek/structlog/pull/658) ## [24.4.0](https://github.com/hynek/structlog/compare/24.3.0...24.4.0) - 2024-07-17 diff --git a/src/structlog/dev.py b/src/structlog/dev.py index 7e9a541d..a3ae8394 100644 --- a/src/structlog/dev.py +++ b/src/structlog/dev.py @@ -635,7 +635,7 @@ def add_meaningless_arg(arg: str) -> None: self.get_default_level_styles(colors) if level_styles is None else level_styles - ) + ).copy() for key in level_to_color: level_to_color[key] += styles.bright diff --git a/tests/test_dev.py b/tests/test_dev.py index 10597dd0..1193c040 100644 --- a/tests/test_dev.py +++ b/tests/test_dev.py @@ -614,6 +614,19 @@ def test_enforces_presence_of_exactly_one_default_formatter(self): ] ) + def test_does_not_modify_styles(self): + """ + Instantiating ConsoleRenderer should not modify the styles passed in. + + Ref #643 + """ + styles = {"info": "something"} + copy = styles.copy() + + dev.ConsoleRenderer(level_styles=styles) + + assert copy == styles + class TestSetExcInfo: def test_wrong_name(self):