Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita47e46d

Browse files
committed
Use zero-argument super() where applicable
This replaces 2-argument super(...) calls with zero-argumentsuper() calls, where doing so preserves the exact semantics. Thisturns out to be everywhere in the actual code (now all uses of thesuper builtin are calls to it with zero arguments), and also inmost places code was discussed in comments.The single exception, occurring in comments (technically a stringliteral, but being used as a comment), appears ingit.objects.util.TraversableIterableObj, where super(Commit, self),rather than super(TraversableIterableObj, self) which would havethe same meaning as super(), is shown. It may be that this shouldbe changed, but such a revision would not signify identicalsemantics, and may require other changes to preserve or recoverclarity or documentary accuracy.
1 parent36a3b76 commita47e46d

File tree

24 files changed

+64
-66
lines changed

24 files changed

+64
-66
lines changed

‎git/cmd.py

Lines changed: 2 additions & 2 deletions
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)forninversion_numbers.split(".")[:4]ifn.isdigit()),
766766
)
767767
else:
768-
super(Git,self)._set_cache_(attr)
768+
super()._set_cache_(attr)
769769
# END handle version info
770770

771771
@property

‎git/config.py

Lines changed: 15 additions & 15 deletions
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
returnnew_type
112112

113113

@@ -178,7 +178,7 @@ def __del__(self) -> None:
178178
def__getattr__(self,attr:str)->Any:
179179
ifattrinself._valid_attrs_:
180180
returnlambda*args,**kwargs:self._call_config(attr,*args,**kwargs)
181-
returnsuper(SectionConstraint,self).__getattribute__(attr)
181+
returnsuper().__getattribute__(attr)
182182

183183
def_call_config(self,method:str,*args:Any,**kwargs:Any)->Any:
184184
"""Call the configuration at the given method which must take a section name
@@ -207,36 +207,36 @@ class _OMD(OrderedDict_OMD):
207207
"""Ordered multi-dict."""
208208

209209
def__setitem__(self,key:str,value:_T)->None:
210-
super(_OMD,self).__setitem__(key, [value])
210+
super().__setitem__(key, [value])
211211

212212
defadd(self,key:str,value:Any)->None:
213213
ifkeynotinself:
214-
super(_OMD,self).__setitem__(key, [value])
214+
super().__setitem__(key, [value])
215215
returnNone
216-
super(_OMD,self).__getitem__(key).append(value)
216+
super().__getitem__(key).append(value)
217217

218218
defsetall(self,key:str,values:List[_T])->None:
219-
super(_OMD,self).__setitem__(key,values)
219+
super().__setitem__(key,values)
220220

221221
def__getitem__(self,key:str)->Any:
222-
returnsuper(_OMD,self).__getitem__(key)[-1]
222+
returnsuper().__getitem__(key)[-1]
223223

224224
defgetlast(self,key:str)->Any:
225-
returnsuper(_OMD,self).__getitem__(key)[-1]
225+
returnsuper().__getitem__(key)[-1]
226226

227227
defsetlast(self,key:str,value:Any)->None:
228228
ifkeynotinself:
229-
super(_OMD,self).__setitem__(key, [value])
229+
super().__setitem__(key, [value])
230230
return
231231

232-
prior=super(_OMD,self).__getitem__(key)
232+
prior=super().__getitem__(key)
233233
prior[-1]=value
234234

235235
defget(self,key:str,default:Union[_T,None]=None)->Union[_T,None]:
236-
returnsuper(_OMD,self).get(key, [default])[-1]
236+
returnsuper().get(key, [default])[-1]
237237

238238
defgetall(self,key:str)->List[_T]:
239-
returnsuper(_OMD,self).__getitem__(key)
239+
returnsuper().__getitem__(key)
240240

241241
defitems(self)->List[Tuple[str,_T]]:# type: ignore[override]
242242
"""List of (key, last value for key)."""
@@ -680,7 +680,7 @@ def write_section(name: str, section_dict: _OMD) -> None:
680680

681681
defitems(self,section_name:str)->List[Tuple[str,str]]:# type: ignore[override]
682682
""":return: list((option, value), ...) pairs of all items in the given section"""
683-
return [(k,v)fork,vinsuper(GitConfigParser,self).items(section_name)ifk!="__name__"]
683+
return [(k,v)fork,vinsuper().items(section_name)ifk!="__name__"]
684684

685685
defitems_all(self,section_name:str)->List[Tuple[str,List[str]]]:
686686
""":return: list((option, [values...]), ...) pairs of all items in the given section"""
@@ -748,7 +748,7 @@ def _assure_writable(self, method_name: str) -> None:
748748

749749
defadd_section(self,section:str)->None:
750750
"""Assures added options will stay in order"""
751-
returnsuper(GitConfigParser,self).add_section(section)
751+
returnsuper().add_section(section)
752752

753753
@property
754754
defread_only(self)->bool:
@@ -899,7 +899,7 @@ def rename_section(self, section: str, new_name: str) -> "GitConfigParser":
899899
ifself.has_section(new_name):
900900
raiseValueError("Destination section '%s' already exists"%new_name)
901901

902-
super(GitConfigParser,self).add_section(new_name)
902+
super().add_section(new_name)
903903
new_section=self._sections[new_name]
904904
fork,vsinself.items_all(section):
905905
new_section.setall(k,vs)

‎git/db.py

Lines changed: 1 addition & 1 deletion
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
definfo(self,binsha:bytes)->OInfo:

‎git/exc.py

Lines changed: 3 additions & 3 deletions
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
classCheckoutError(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

‎git/index/base.py

Lines changed: 2 additions & 2 deletions
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
ifself.repo.git_dir:
@@ -1425,4 +1425,4 @@ def diff(
14251425
raiseValueError("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-
returnsuper(IndexFile,self).diff(other,paths,create_patch,**kwargs)
1428+
returnsuper().diff(other,paths,create_patch,**kwargs)

‎git/objects/base.py

Lines changed: 4 additions & 4 deletions
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
assertlen(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"""
@@ -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
ifmodeisnotNone:
195195
self.mode=mode
196196
ifpathisnotNone:
@@ -212,7 +212,7 @@ def _set_cache_(self, attr: str) -> None:
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

‎git/objects/commit.py

Lines changed: 2 additions & 2 deletions
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
iftreeisnotNone:
152152
assertisinstance(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

‎git/objects/submodule/base.py

Lines changed: 3 additions & 3 deletions
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
ifurlisnotNone:
@@ -154,7 +154,7 @@ def _set_cache_(self, attr: str) -> None:
154154
elifattr=="_name":
155155
raiseAttributeError("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
returnself._name==other._name
179179

180180
def__ne__(self,other:object)->bool:

‎git/objects/submodule/root.py

Lines changed: 1 addition & 1 deletion
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,

‎git/objects/submodule/util.py

Lines changed: 2 additions & 2 deletions
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
defset_submodule(self,submodule:"Submodule")->None:
@@ -107,7 +107,7 @@ def flush_to_index(self) -> None:
107107

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp