Repository navigation
fix(compat): restore __class_getitem__ on StreamHandler and LoggerAdapter - #10
Closed
coseto6125 wants to merge 1 commit into
Closed
coseto6125 wants to merge 1 commit into
coseto6125 wants to merge 1 commit into
Conversation
…pter
cpython's Lib/logging/__init__.py makes both classes generic:
logging/__init__.py:1187 class StreamHandler ...
__class_getitem__ = classmethod(GenericAlias)
logging/__init__.py:1995 class LoggerAdapter ...
__class_getitem__ = classmethod(GenericAlias)
logxide's replacements did not carry those lines, so once
sys.modules["logging"] is swapped, `logging.LoggerAdapter[...]` raises
TypeError. Any third-party library that subscripts either class at
runtime breaks.
websockets 17.0 does exactly that. 16.0 kept the subscript behind a
TYPE_CHECKING guard with a runtime fallback; 17.0 dropped the fallback
and evaluates `logging.LoggerAdapter[Any]` at module import:
import logxide
import websockets.typing
TypeError: type 'LoggerAdapter' is not subscriptable
Sanic imports websockets, so every Sanic entry point in a project using
logxide fails to start.
Logger is deliberately left alone — stdlib's Logger is not subscriptable
either, and a test pins that so the fix does not overreach.
Closes Indosaram#9
Owner
|
Merged into main via commit 2846611 (conflicts in CHANGELOG.md and compat_handlers.py resolved against v0.3.0). Thank you @coseto6125! |
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.
Fixes #9.
What
cpython's
Lib/logging/__init__.pymakes two classes generic:logxide's replacements did not carry those lines. Since logxide swaps
sys.modules["logging"], any third-party library that subscripts either class at runtime gets logxide's non-generic class and raisesTypeError.Why it matters now
websockets 17.0 removed the
TYPE_CHECKINGguard around that subscript, so it is evaluated at import time:Sanic imports websockets, so every Sanic entry point in a project using logxide fails to start. We hit this on a production service and are currently carrying a local monkeypatch.
Scope
Loggeris deliberately left alone — stdlib'sLoggeris not subscriptable either, so logxide already matches there.test_logger_is_not_subscriptable_like_stdlibpins that, so the fix cannot silently overreach.Verification
logxide 0.2.2 + websockets 17.0.1 on Python 3.14.6, patch applied to the installed package:
New tests, run against the installed package:
The one that passes either way is the
Logger-stays-non-generic guard, which is the intended behavior.I could not run
cargo test/ the fullpytest tests/locally — no Rust toolchain on this machine, so the extension module could not be built. The change is pure Python and touches no Rust, but CI should confirm the rest of the suite.Related
#8 reports
AttributeError: module 'logging' has no attribute 'RootLogger'breaking joblib/cloudpickle. Same shape, different attribute — the replacement module does not reproduce everything stdlib exposes.Comparing the two surfaces on 3.14.6, 23 public names resolve on stdlib
loggingbut raiseAttributeErrorunder logxide. About half are incidental re-exports (os,re,sys,time,threading,traceback,warnings,weakref,collections,io,atexit,Template,GenericAlias); the rest are real logging API:A parity test that diffs the two surfaces would catch this whole class of bug up front. Happy to send that as a separate PR if you want it — I left it out here to keep this one reviewable.