From 741dfd392d2b79c4f4b84ed2e08e4838714469bf Mon Sep 17 00:00:00 2001 From: Eliah Kagan Date: Tue, 23 Jan 2024 18:17:00 -0500 Subject: [PATCH 1/2] Deprecate git.util.NullHandler 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. --- git/util.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/git/util.py b/git/util.py index 5ccd2b04c..4a284b785 100644 --- a/git/util.py +++ b/git/util.py @@ -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 From 01e768b8b8b1af0b56d35ee244e54cae1b22126c Mon Sep 17 00:00:00 2001 From: Eliah Kagan Date: Tue, 23 Jan 2024 18:43:27 -0500 Subject: [PATCH 2/2] Remove git.util.NullHandler git.util has an __all__ attribute, which does not list NullHandler. As NullHandler is not otherwise documented to be public, removing it is not a breaking change, and there is no need for a deprecation period or to wait until the next major version of GitPython. See 741dfd3 for information about its history. --- git/util.py | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/git/util.py b/git/util.py index 4a284b785..27ca06bcd 100644 --- a/git/util.py +++ b/git/util.py @@ -1292,23 +1292,3 @@ def list_items(cls, repo: "Repo", *args: Any, **kwargs: Any) -> Any: # } END classes - - -class NullHandler(logging.Handler): - """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