Fix logger level not restored correctly for empty byte sequences#701
Merged
Ousret merged 1 commit intojawah:masterfrom Mar 6, 2026
Merged
Conversation
When from_bytes() is called with explain=True on an empty byte
sequence, the logger level was restored using:
logger.setLevel(previous_logger_level or logging.WARNING)
If the logger was at NOTSET (level 0, the default), the 'or'
expression evaluates to logging.WARNING (30) instead of 0,
permanently changing the logger level from NOTSET to WARNING.
All other exit paths in the same function correctly use just
previous_logger_level without the 'or' fallback.
Merged
Ousret
added a commit
that referenced
this pull request
Mar 6, 2026
## [3.4.5](3.4.4...3.4.5) (2026-03-06) ### Changed - Update `setuptools` constraint to `setuptools>=68,<=82`. - Raised upper bound of mypyc for the optional pre-built extension to v1.19.1 ### Fixed - Add explicit link to lib math in our optimized build. (#692) - Logger level not restored correctly for empty byte sequences. (#701) - TypeError when passing bytearray to from_bytes. (#703) ### Misc - Applied safe micro-optimizations in both our noise detector and language detector. - Rewrote the `query_yes_no` function (inside CLI) to avoid using ambiguous licensed code. - Added `cd.py` submodule into mypyc optional compilation to reduce further the performance impact.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix incorrect logger level restoration after
from_bytes(b"", explain=True).Problem
When
from_bytes()is called withexplain=Trueon an empty byte sequence, the early-return path restores the logger level with:The default logger level is
NOTSET(integer0). Because0is falsy, theorexpression evaluates tologging.WARNING(30) instead of0:This permanently changes the
charset_normalizerlogger fromNOTSETtoWARNING. The effect: any user-configured handler expectingDEBUGorINFOmessages from the library will silently stop receiving them after a singlefrom_bytes(b"", explain=True)call.All other exit paths in the same function correctly restore the level without the
orfallback:Only the empty-sequence path at line 81 had the bug.
Fix
Remove the
or logging.WARNINGfallback so it behaves the same as every other exit path.