Skip to content

Commit 1755b1d

Browse files
authored
Merge pull request #1726 from EliahKagan/super
Use zero-argument super()
2 parents 6cef9c0 + 9113177 commit 1755b1d

25 files changed

+70
-77
lines changed

Diff for: git/cmd.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,7 @@ def __init__(self, working_dir: Union[None, PathLike] = None):
718718
It is meant to be the working tree directory if available, or the
719719
``.git`` directory in case of bare repositories.
720720
"""
721-
super(Git, self).__init__()
721+
super().__init__()
722722
self._working_dir = expand_path(working_dir)
723723
self._git_options: Union[List[str], Tuple[str, ...]] = ()
724724
self._persistent_git_options: List[str] = []
@@ -765,7 +765,7 @@ def _set_cache_(self, attr: str) -> None:
765765
tuple(int(n) for n in version_numbers.split(".")[:4] if n.isdigit()),
766766
)
767767
else:
768-
super(Git, self)._set_cache_(attr)
768+
super()._set_cache_(attr)
769769
# END handle version info
770770

771771
@property

Diff for: git/config.py

+16-15
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def __new__(cls, name: str, bases: Tuple, clsdict: Dict[str, Any]) -> "MetaParse
107107
# END for each base
108108
# END if mutating methods configuration is set
109109

110-
new_type = super(MetaParserBuilder, cls).__new__(cls, name, bases, clsdict)
110+
new_type = super().__new__(cls, name, bases, clsdict)
111111
return new_type
112112

113113

@@ -150,6 +150,7 @@ class SectionConstraint(Generic[T_ConfigParser]):
150150
"""
151151

152152
__slots__ = ("_config", "_section_name")
153+
153154
_valid_attrs_ = (
154155
"get_value",
155156
"set_value",
@@ -177,7 +178,7 @@ def __del__(self) -> None:
177178
def __getattr__(self, attr: str) -> Any:
178179
if attr in self._valid_attrs_:
179180
return lambda *args, **kwargs: self._call_config(attr, *args, **kwargs)
180-
return super(SectionConstraint, self).__getattribute__(attr)
181+
return super().__getattribute__(attr)
181182

182183
def _call_config(self, method: str, *args: Any, **kwargs: Any) -> Any:
183184
"""Call the configuration at the given method which must take a section name
@@ -206,36 +207,36 @@ class _OMD(OrderedDict_OMD):
206207
"""Ordered multi-dict."""
207208

208209
def __setitem__(self, key: str, value: _T) -> None:
209-
super(_OMD, self).__setitem__(key, [value])
210+
super().__setitem__(key, [value])
210211

211212
def add(self, key: str, value: Any) -> None:
212213
if key not in self:
213-
super(_OMD, self).__setitem__(key, [value])
214+
super().__setitem__(key, [value])
214215
return None
215-
super(_OMD, self).__getitem__(key).append(value)
216+
super().__getitem__(key).append(value)
216217

217218
def setall(self, key: str, values: List[_T]) -> None:
218-
super(_OMD, self).__setitem__(key, values)
219+
super().__setitem__(key, values)
219220

220221
def __getitem__(self, key: str) -> Any:
221-
return super(_OMD, self).__getitem__(key)[-1]
222+
return super().__getitem__(key)[-1]
222223

223224
def getlast(self, key: str) -> Any:
224-
return super(_OMD, self).__getitem__(key)[-1]
225+
return super().__getitem__(key)[-1]
225226

226227
def setlast(self, key: str, value: Any) -> None:
227228
if key not in self:
228-
super(_OMD, self).__setitem__(key, [value])
229+
super().__setitem__(key, [value])
229230
return
230231

231-
prior = super(_OMD, self).__getitem__(key)
232+
prior = super().__getitem__(key)
232233
prior[-1] = value
233234

234235
def get(self, key: str, default: Union[_T, None] = None) -> Union[_T, None]:
235-
return super(_OMD, self).get(key, [default])[-1]
236+
return super().get(key, [default])[-1]
236237

237238
def getall(self, key: str) -> List[_T]:
238-
return super(_OMD, self).__getitem__(key)
239+
return super().__getitem__(key)
239240

240241
def items(self) -> List[Tuple[str, _T]]: # type: ignore[override]
241242
"""List of (key, last value for key)."""
@@ -679,7 +680,7 @@ def write_section(name: str, section_dict: _OMD) -> None:
679680

680681
def items(self, section_name: str) -> List[Tuple[str, str]]: # type: ignore[override]
681682
""":return: list((option, value), ...) pairs of all items in the given section"""
682-
return [(k, v) for k, v in super(GitConfigParser, self).items(section_name) if k != "__name__"]
683+
return [(k, v) for k, v in super().items(section_name) if k != "__name__"]
683684

684685
def items_all(self, section_name: str) -> List[Tuple[str, List[str]]]:
685686
""":return: list((option, [values...]), ...) pairs of all items in the given section"""
@@ -747,7 +748,7 @@ def _assure_writable(self, method_name: str) -> None:
747748

748749
def add_section(self, section: str) -> None:
749750
"""Assures added options will stay in order"""
750-
return super(GitConfigParser, self).add_section(section)
751+
return super().add_section(section)
751752

752753
@property
753754
def read_only(self) -> bool:
@@ -898,7 +899,7 @@ def rename_section(self, section: str, new_name: str) -> "GitConfigParser":
898899
if self.has_section(new_name):
899900
raise ValueError("Destination section '%s' already exists" % new_name)
900901

901-
super(GitConfigParser, self).add_section(new_name)
902+
super().add_section(new_name)
902903
new_section = self._sections[new_name]
903904
for k, vs in self.items_all(section):
904905
new_section.setall(k, vs)

Diff for: git/db.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class GitCmdObjectDB(LooseObjectDB):
3434

3535
def __init__(self, root_path: PathLike, git: "Git") -> None:
3636
"""Initialize this instance with the root and a git command."""
37-
super(GitCmdObjectDB, self).__init__(root_path)
37+
super().__init__(root_path)
3838
self._git = git
3939

4040
def info(self, binsha: bytes) -> OInfo:

Diff for: git/exc.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ class GitCommandNotFound(CommandError):
137137
the GIT_PYTHON_GIT_EXECUTABLE environment variable."""
138138

139139
def __init__(self, command: Union[List[str], Tuple[str], str], cause: Union[str, Exception]) -> None:
140-
super(GitCommandNotFound, self).__init__(command, cause)
140+
super().__init__(command, cause)
141141
self._msg = "Cmd('%s') not found%s"
142142

143143

@@ -151,7 +151,7 @@ def __init__(
151151
stderr: Union[bytes, str, None] = None,
152152
stdout: Union[bytes, str, None] = None,
153153
) -> None:
154-
super(GitCommandError, self).__init__(command, status, stderr, stdout)
154+
super().__init__(command, status, stderr, stdout)
155155

156156

157157
class CheckoutError(GitError):
@@ -207,7 +207,7 @@ def __init__(
207207
stderr: Union[bytes, str, None] = None,
208208
stdout: Union[bytes, str, None] = None,
209209
) -> None:
210-
super(HookExecutionError, self).__init__(command, status, stderr, stdout)
210+
super().__init__(command, status, stderr, stdout)
211211
self._msg = "Hook('%s') failed%s"
212212

213213

Diff for: git/index/base.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ def _set_cache_(self, attr: str) -> None:
153153

154154
self._deserialize(stream)
155155
else:
156-
super(IndexFile, self)._set_cache_(attr)
156+
super()._set_cache_(attr)
157157

158158
def _index_path(self) -> PathLike:
159159
if self.repo.git_dir:
@@ -1425,4 +1425,4 @@ def diff(
14251425
raise ValueError("other must be None, Diffable.Index, a Tree or Commit, was %r" % other)
14261426

14271427
# Diff against working copy - can be handled by superclass natively.
1428-
return super(IndexFile, self).diff(other, paths, create_patch, **kwargs)
1428+
return super().diff(other, paths, create_patch, **kwargs)

Diff for: git/objects/base.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def __init__(self, repo: "Repo", binsha: bytes):
6262
6363
:param binsha: 20 byte SHA1
6464
"""
65-
super(Object, self).__init__()
65+
super().__init__()
6666
self.repo = repo
6767
self.binsha = binsha
6868
assert len(binsha) == 20, "Require 20 byte binary sha, got %r, len = %i" % (
@@ -108,7 +108,7 @@ def _set_cache_(self, attr: str) -> None:
108108
self.size = oinfo.size # type: int
109109
# assert oinfo.type == self.type, _assertion_msg_format % (self.binsha, oinfo.type, self.type)
110110
else:
111-
super(Object, self)._set_cache_(attr)
111+
super()._set_cache_(attr)
112112

113113
def __eq__(self, other: Any) -> bool:
114114
""":return: True if the objects have the same SHA1"""
@@ -137,7 +137,7 @@ def __repr__(self) -> str:
137137
@property
138138
def hexsha(self) -> str:
139139
""":return: 40 byte hex version of our 20 byte binary sha"""
140-
# b2a_hex produces bytes
140+
# b2a_hex produces bytes.
141141
return bin_to_hex(self.binsha).decode("ascii")
142142

143143
@property
@@ -190,7 +190,7 @@ def __init__(
190190
Path may not be set if the index object has been created directly, as it
191191
cannot be retrieved without knowing the parent tree.
192192
"""
193-
super(IndexObject, self).__init__(repo, binsha)
193+
super().__init__(repo, binsha)
194194
if mode is not None:
195195
self.mode = mode
196196
if path is not None:
@@ -206,13 +206,13 @@ def __hash__(self) -> int:
206206

207207
def _set_cache_(self, attr: str) -> None:
208208
if attr in IndexObject.__slots__:
209-
# they cannot be retrieved lateron ( not without searching for them )
209+
# They cannot be retrieved later on (not without searching for them).
210210
raise AttributeError(
211211
"Attribute '%s' unset: path and mode attributes must have been set during %s object creation"
212212
% (attr, type(self).__name__)
213213
)
214214
else:
215-
super(IndexObject, self)._set_cache_(attr)
215+
super()._set_cache_(attr)
216216
# END handle slot attribute
217217

218218
@property

Diff for: git/objects/commit.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ def __init__(
146146
as what time.altzone returns. The sign is inverted compared to git's
147147
UTC timezone.
148148
"""
149-
super(Commit, self).__init__(repo, binsha)
149+
super().__init__(repo, binsha)
150150
self.binsha = binsha
151151
if tree is not None:
152152
assert isinstance(tree, Tree), "Tree needs to be a Tree instance, was %s" % type(tree)
@@ -218,7 +218,7 @@ def _set_cache_(self, attr: str) -> None:
218218
_binsha, _typename, self.size, stream = self.repo.odb.stream(self.binsha)
219219
self._deserialize(BytesIO(stream.read()))
220220
else:
221-
super(Commit, self)._set_cache_(attr)
221+
super()._set_cache_(attr)
222222
# END handle attrs
223223

224224
@property

Diff for: git/objects/submodule/base.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def __init__(
124124
:param branch_path: Full (relative) path to ref to checkout when cloning the
125125
remote repository.
126126
"""
127-
super(Submodule, self).__init__(repo, binsha, mode, path)
127+
super().__init__(repo, binsha, mode, path)
128128
self.size = 0
129129
self._parent_commit = parent_commit
130130
if url is not None:
@@ -154,7 +154,7 @@ def _set_cache_(self, attr: str) -> None:
154154
elif attr == "_name":
155155
raise AttributeError("Cannot retrieve the name of a submodule if it was not set initially")
156156
else:
157-
super(Submodule, self)._set_cache_(attr)
157+
super()._set_cache_(attr)
158158
# END handle attribute name
159159

160160
@classmethod
@@ -174,7 +174,7 @@ def __eq__(self, other: Any) -> bool:
174174
"""Compare with another submodule."""
175175
# We may only compare by name as this should be the ID they are hashed with.
176176
# Otherwise this type wouldn't be hashable.
177-
# return self.path == other.path and self.url == other.url and super(Submodule, self).__eq__(other)
177+
# return self.path == other.path and self.url == other.url and super().__eq__(other)
178178
return self._name == other._name
179179

180180
def __ne__(self, other: object) -> bool:

Diff for: git/objects/submodule/root.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class RootModule(Submodule):
5555

5656
def __init__(self, repo: "Repo"):
5757
# repo, binsha, mode=None, path=None, name = None, parent_commit=None, url=None, ref=None)
58-
super(RootModule, self).__init__(
58+
super().__init__(
5959
repo,
6060
binsha=self.NULL_BIN_SHA,
6161
mode=self.k_default_mode,

Diff for: git/objects/submodule/util.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def __init__(self, *args: Any, **kwargs: Any) -> None:
7979
self._smref: Union["ReferenceType[Submodule]", None] = None
8080
self._index = None
8181
self._auto_write = True
82-
super(SubmoduleConfigParser, self).__init__(*args, **kwargs)
82+
super().__init__(*args, **kwargs)
8383

8484
# { Interface
8585
def set_submodule(self, submodule: "Submodule") -> None:
@@ -107,7 +107,7 @@ def flush_to_index(self) -> None:
107107

108108
# { Overridden Methods
109109
def write(self) -> None: # type: ignore[override]
110-
rval: None = super(SubmoduleConfigParser, self).write()
110+
rval: None = super().write()
111111
self.flush_to_index()
112112
return rval
113113

Diff for: git/objects/tag.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def __init__(
6464
The timezone that the authored_date is in, in a format similar
6565
to :attr:`time.altzone`.
6666
"""
67-
super(TagObject, self).__init__(repo, binsha)
67+
super().__init__(repo, binsha)
6868
if object is not None:
6969
self.object: Union["Commit", "Blob", "Tree", "TagObject"] = object
7070
if tag is not None:
@@ -108,4 +108,4 @@ def _set_cache_(self, attr: str) -> None:
108108
self.message = ""
109109
# END check our attributes
110110
else:
111-
super(TagObject, self)._set_cache_(attr)
111+
super()._set_cache_(attr)

Diff for: git/objects/tree.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ def __init__(
237237
mode: int = tree_id << 12,
238238
path: Union[PathLike, None] = None,
239239
):
240-
super(Tree, self).__init__(repo, binsha, mode, path)
240+
super().__init__(repo, binsha, mode, path)
241241

242242
@classmethod
243243
def _get_intermediate_items(
@@ -254,7 +254,7 @@ def _set_cache_(self, attr: str) -> None:
254254
ostream = self.repo.odb.stream(self.binsha)
255255
self._cache: List[TreeCacheTup] = tree_entries_from_data(ostream.read())
256256
else:
257-
super(Tree, self)._set_cache_(attr)
257+
super()._set_cache_(attr)
258258
# END handle attribute
259259

260260
def _iter_convert_to_object(self, iterable: Iterable[TreeCacheTup]) -> Iterator[IndexObjUnion]:
@@ -352,13 +352,13 @@ def traverse(
352352
# def is_tree_traversed(inp: Tuple) -> TypeGuard[Tuple[Iterator[Union['Tree', 'Blob', 'Submodule']]]]:
353353
# return all(isinstance(x, (Blob, Tree, Submodule)) for x in inp[1])
354354

355-
# ret = super(Tree, self).traverse(predicate, prune, depth, branch_first, visit_once, ignore_self)
355+
# ret = super().traverse(predicate, prune, depth, branch_first, visit_once, ignore_self)
356356
# ret_tup = itertools.tee(ret, 2)
357357
# assert is_tree_traversed(ret_tup), f"Type is {[type(x) for x in list(ret_tup[0])]}"
358358
# return ret_tup[0]"""
359359
return cast(
360360
Union[Iterator[IndexObjUnion], Iterator[TraversedTreeTup]],
361-
super(Tree, self)._traverse(
361+
super()._traverse(
362362
predicate,
363363
prune,
364364
depth, # type: ignore
@@ -374,7 +374,7 @@ def list_traverse(self, *args: Any, **kwargs: Any) -> IterableList[IndexObjUnion
374374
traverse()
375375
Tree -> IterableList[Union['Submodule', 'Tree', 'Blob']]
376376
"""
377-
return super(Tree, self)._list_traverse(*args, **kwargs)
377+
return super()._list_traverse(*args, **kwargs)
378378

379379
# List protocol
380380

Diff for: git/objects/util.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ class TraversableIterableObj(IterableObj, Traversable):
577577
TIobj_tuple = Tuple[Union[T_TIobj, None], T_TIobj]
578578

579579
def list_traverse(self: T_TIobj, *args: Any, **kwargs: Any) -> IterableList[T_TIobj]:
580-
return super(TraversableIterableObj, self)._list_traverse(*args, **kwargs)
580+
return super()._list_traverse(*args, **kwargs)
581581

582582
@overload # type: ignore
583583
def traverse(self: T_TIobj) -> Iterator[T_TIobj]:
@@ -652,7 +652,5 @@ def is_commit_traversed(inp: Tuple) -> TypeGuard[Tuple[Iterator[Tuple['Commit',
652652
"""
653653
return cast(
654654
Union[Iterator[T_TIobj], Iterator[Tuple[Union[None, T_TIobj], T_TIobj]]],
655-
super(TraversableIterableObj, self)._traverse(
656-
predicate, prune, depth, branch_first, visit_once, ignore_self, as_edge # type: ignore
657-
),
655+
super()._traverse(predicate, prune, depth, branch_first, visit_once, ignore_self, as_edge), # type: ignore
658656
)

Diff for: git/refs/head.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class HEAD(SymbolicReference):
3939
def __init__(self, repo: "Repo", path: PathLike = _HEAD_NAME):
4040
if path != self._HEAD_NAME:
4141
raise ValueError("HEAD instance must point to %r, got %r" % (self._HEAD_NAME, path))
42-
super(HEAD, self).__init__(repo, path)
42+
super().__init__(repo, path)
4343
self.commit: "Commit"
4444

4545
def orig_head(self) -> SymbolicReference:

Diff for: git/refs/log.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ class RefLog(List[RefLogEntry], Serializable):
155155
__slots__ = ("_path",)
156156

157157
def __new__(cls, filepath: Union[PathLike, None] = None) -> "RefLog":
158-
inst = super(RefLog, cls).__new__(cls)
158+
inst = super().__new__(cls)
159159
return inst
160160

161161
def __init__(self, filepath: Union[PathLike, None] = None):

0 commit comments

Comments
 (0)