Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

fix: Use a noop with the same signature as the real one for make_filtering_bound_logger #401

Merged
merged 1 commit into from
Mar 10, 2022
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
3 changes: 3 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ Backward-incompatible changes:

- Python 3.6 is not supported anymore.
- Pickling is now only possible with protocol version 3 and newer.
- ``structlog.make_filtering_bound_logger()`` now returns a method with the same signature for all log levels, whether they are active or not.
This ensures that invalid calls to inactive log levels are caught immediately and don't explode once the log level changes.
`#401 <https://github.com/hynek/structlog/pull/401>`_


Deprecations:
Expand Down
2 changes: 1 addition & 1 deletion src/structlog/_log_levels.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def add_log_level(
return event_dict


def _nop(*args: Any, **kw: Any) -> Any:
def _nop(self: Any, event: str, **kw: Any) -> Any:
return None
GriceTurrble marked this conversation as resolved.
Show resolved Hide resolved


Expand Down
24 changes: 23 additions & 1 deletion tests/test_log_levels.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,34 @@ def test_exact_level(self, bl, cl):

def test_one_below(self, bl, cl):
"""
if log level is exactly the min_level, log.
if log level is below the min_level, don't log.
hynek marked this conversation as resolved.
Show resolved Hide resolved
"""
bl.debug("nope")

assert [] == cl.calls

def test_filter_bound_below_missing_event_string(self, bl, cl):
"""
Missing event arg causes exception below min_level.
"""
with pytest.raises(TypeError) as exc_info:
bl.debug(missing="event string!")
assert exc_info.type is TypeError

message = "missing 1 required positional argument: 'event'"
GriceTurrble marked this conversation as resolved.
Show resolved Hide resolved
assert message in exc_info.value.args[0]

def test_filter_bound_exact_missing_event_string(self, bl, cl):
"""
Missing event arg causes exception even at min_level.
"""
with pytest.raises(TypeError) as exc_info:
bl.info(missing="event string!")
assert exc_info.type is TypeError

message = "missing 1 required positional argument: 'event'"
GriceTurrble marked this conversation as resolved.
Show resolved Hide resolved
assert message in exc_info.value.args[0]

def test_exception(self, bl, cl):
"""
exception ensures that exc_info is set to True, unless it's already
Expand Down