Skip to content

Commit

Permalink
Deprecate git.util.NullHandler
Browse files Browse the repository at this point in the history
The NullHandler class in git.util was added when merging #300, to
allow a noop handler to be used on Python 2.6, since the standard
library logging.NullHandler class was added in Python 2.7.

When introduced in d1a9a23, the git.util.NullHandler class was also
patched into the logging module, but that has no longer been done
since 2fced2e (#979), nor does GitPython make other use of it.

This also changes the parameter type annotation on the emit method
from `object` to `logging.LogRecord`, which is the expeced type.
  • Loading branch information
EliahKagan committed Jan 23, 2024
1 parent d28c20b commit 741dfd3
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion git/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -1295,5 +1295,20 @@ def list_items(cls, repo: "Repo", *args: Any, **kwargs: Any) -> Any:


class NullHandler(logging.Handler):
def emit(self, record: object) -> None:
"""Deprecated, use :class:`logging.NullHandler` instead.
This noop handler is like :class:`~logging.NullHandler` in the standard library,
which should be used instead, because it is now always available, and it overrides
more logging methods to make them noop. This class only overrides :meth:`emit`.
"""

def __init__(self, level: int = logging.NOTSET) -> None:
warnings.warn(
"NullHandler in git.util is deprecated. Use logging.NullHandler instead.",
DeprecationWarning,
stacklevel=2,
)
super().__init__(level)

def emit(self, record: logging.LogRecord) -> None:
pass

0 comments on commit 741dfd3

Please sign in to comment.