Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Stop mutating styles in ConsoleRenderer #669

Merged
merged 1 commit into from
Nov 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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