Add level and msg type hints to MultiProcessAdapter.log - #4125
Open
RudrenduPaul wants to merge 1 commit into
Open
Add level and msg type hints to MultiProcessAdapter.log#4125RudrenduPaul wants to merge 1 commit into
RudrenduPaul wants to merge 1 commit into
Conversation
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.
What this PR does
Adds type hints to the
levelandmsgparameters ofMultiProcessAdapter.log()insrc/accelerate/logging.py:MultiProcessAdaptersubclasseslogging.LoggerAdapter, and this matchesthe standard library's own typeshed signature for
LoggerAdapter.log(self, level: int, msg: object, ...)—levelis alwaysan integer logging level (e.g.
logging.INFO), andmsgis typed asobjectrather thanstrbecause Python's logging module accepts anyobject with a
__str__(including lazy-formatting helper objects), andthat's exactly how this method is exercised elsewhere via
self.isEnabledFor(level)andself.process(msg, kwargs).This is a self-identified typing-consistency follow-up (no linked issue) —
a small companion to my other open PR (#4123, type hints in
utils/imports.py), which touches a different file in the same repo.No behaviour change
Type-hint-only change. No logic was modified. The file already has
from __future__ import annotationsat the top, so this adds no runtimeoverhead.
Testing
ruff check src/accelerate/logging.py— 1 pre-existing finding(unrelated
functools.lru_cacheonwarning_once), not on the changedline, not introduced by this change (verified against upstream
mainbefore/after via
git stash).ruff format --diff src/accelerate/logging.py— no diff, file alreadyformatted.