Skip to content

Commit

Permalink
Stop mutating styles in ConsoleRenderer
Browse files Browse the repository at this point in the history
Fixes #643
  • Loading branch information
hynek committed Nov 9, 2024
1 parent 8da1ba5 commit 1081e71
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/structlog/dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions tests/test_dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 1081e71

Please sign in to comment.