From f78587fd9376d3578fa816e8c99f5d8dd657332c Mon Sep 17 00:00:00 2001 From: Eliah Kagan Date: Wed, 18 Oct 2023 11:57:50 -0400 Subject: [PATCH] Remove explicit inheritance from object Within the git module. In Python 2, it was necessary to inherit from object to have a new-style class. In Python 3, all classes are new-style classes, and inheritance from object is implied. Usually, removing explicit inheritance from object is only a small clarity benefit while modernizing Python codebases. However, in GitPython, the benefit is greater, because it is possible to confuse object (the root of the Python class hierarchy) with Object (the root of the GitPython subhierarchy of classes representing things in the git object model). --- git/cmd.py | 4 ++-- git/diff.py | 6 +++--- git/index/typ.py | 2 +- git/index/util.py | 2 +- git/objects/tree.py | 2 +- git/objects/util.py | 2 +- git/refs/symbolic.py | 2 +- git/repo/base.py | 2 +- git/util.py | 10 +++++----- 9 files changed, 16 insertions(+), 16 deletions(-) diff --git a/git/cmd.py b/git/cmd.py index f8b6c9e78..384a39077 100644 --- a/git/cmd.py +++ b/git/cmd.py @@ -490,7 +490,7 @@ def check_unsafe_options(cls, options: List[str], unsafe_options: List[str]) -> f"{unsafe_option} is not allowed, use `allow_unsafe_options=True` to allow it." ) - class AutoInterrupt(object): + class AutoInterrupt: """Process wrapper that terminates the wrapped process on finalization. This kills/interrupts the stored process instance once this instance goes out of @@ -602,7 +602,7 @@ def read_all_from_possibly_closed_stream(stream: Union[IO[bytes], None]) -> byte # END auto interrupt - class CatFileContentStream(object): + class CatFileContentStream: """Object representing a sized read-only stream returning the contents of an object. diff --git a/git/diff.py b/git/diff.py index 1fde4d676..d5740a7fc 100644 --- a/git/diff.py +++ b/git/diff.py @@ -79,7 +79,7 @@ def decode_path(path: bytes, has_ab_prefix: bool = True) -> Optional[bytes]: return path -class Diffable(object): +class Diffable: """Common interface for all objects that can be diffed against another object of compatible type. @@ -90,7 +90,7 @@ class Diffable(object): __slots__ = () - class Index(object): + class Index: """Stand-in indicating you want to diff against the index.""" def _process_diff_args( @@ -252,7 +252,7 @@ def iter_change_type(self, change_type: Lit_change_type) -> Iterator[T_Diff]: # END for each diff -class Diff(object): +class Diff: """A Diff contains diff information between two Trees. It contains two sides a and b of the diff, members are prefixed with diff --git a/git/index/typ.py b/git/index/typ.py index 046df6e83..7b86cae55 100644 --- a/git/index/typ.py +++ b/git/index/typ.py @@ -32,7 +32,7 @@ # } END invariants -class BlobFilter(object): +class BlobFilter: """ Predicate to be used by iter_blobs allowing to filter only return blobs which match the given list of directories or files. diff --git a/git/index/util.py b/git/index/util.py index f52b61b4a..08e49d860 100644 --- a/git/index/util.py +++ b/git/index/util.py @@ -33,7 +33,7 @@ # } END aliases -class TemporaryFileSwap(object): +class TemporaryFileSwap: """Utility class moving a file to a temporary location within the same directory and moving it back on to where on object deletion.""" diff --git a/git/objects/tree.py b/git/objects/tree.py index fec98d6e8..b33da3709 100644 --- a/git/objects/tree.py +++ b/git/objects/tree.py @@ -102,7 +102,7 @@ def merge_sort(a: List[TreeCacheTup], cmp: Callable[[TreeCacheTup, TreeCacheTup] k = k + 1 -class TreeModifier(object): +class TreeModifier: """A utility class providing methods to alter the underlying cache in a list-like fashion. Once all adjustments are complete, the _cache, which really is a reference to diff --git a/git/objects/util.py b/git/objects/util.py index d2c1c0158..5ccb3ec37 100644 --- a/git/objects/util.py +++ b/git/objects/util.py @@ -337,7 +337,7 @@ def parse_actor_and_date(line: str) -> Tuple[Actor, int, int]: # { Classes -class ProcessStreamAdapter(object): +class ProcessStreamAdapter: """Class wiring all calls to the contained Process instance. Use this type to hide the underlying process to provide access only to a specified diff --git a/git/refs/symbolic.py b/git/refs/symbolic.py index 7da957e2f..3587a52d3 100644 --- a/git/refs/symbolic.py +++ b/git/refs/symbolic.py @@ -55,7 +55,7 @@ def _git_dir(repo: "Repo", path: Union[PathLike, None]) -> PathLike: return repo.common_dir -class SymbolicReference(object): +class SymbolicReference: """Special case of a reference that is symbolic. This does not point to a specific commit, but to another diff --git a/git/repo/base.py b/git/repo/base.py index da81698d8..2694282d0 100644 --- a/git/repo/base.py +++ b/git/repo/base.py @@ -108,7 +108,7 @@ class BlameEntry(NamedTuple): orig_linenos: range -class Repo(object): +class Repo: """Represents a git repository and allows you to query references, gather commit information, generate diffs, create and clone repositories query the log. diff --git a/git/util.py b/git/util.py index 29cf12f7c..e61e3c6f5 100644 --- a/git/util.py +++ b/git/util.py @@ -516,7 +516,7 @@ def remove_password_if_present(cmdline: Sequence[str]) -> List[str]: # { Classes -class RemoteProgress(object): +class RemoteProgress: """ Handler providing an interface to parse progress information emitted by git-push and git-fetch and to dispatch callbacks allowing subclasses to react to the progress. @@ -723,7 +723,7 @@ def update(self, *args: Any, **kwargs: Any) -> None: self._callable(*args, **kwargs) -class Actor(object): +class Actor: """Actors hold information about a person acting on the repository. They can be committers and authors or anything with a name and an email as mentioned in the git log entries.""" @@ -847,7 +847,7 @@ def author(cls, config_reader: Union[None, "GitConfigParser", "SectionConstraint return cls._main_actor(cls.env_author_name, cls.env_author_email, config_reader) -class Stats(object): +class Stats: """ Represents stat information as presented by git at the end of a merge. It is created from the output of a diff operation. @@ -908,7 +908,7 @@ def _list_from_string(cls, repo: "Repo", text: str) -> "Stats": return Stats(hsh["total"], hsh["files"]) -class IndexFileSHA1Writer(object): +class IndexFileSHA1Writer: """Wrapper around a file-like object that remembers the SHA1 of the data written to it. It will write a sha when the stream is closed or if the asked for explicitly using write_sha. @@ -942,7 +942,7 @@ def tell(self) -> int: return self.f.tell() -class LockFile(object): +class LockFile: """Provides methods to obtain, check for, and release a file based lock which should be used to handle concurrent access to the same file.