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

Commitac4f7d3

Browse files
committed
Rewrite unnecessary dict/list/tuple calls as literals
1 parent14582df commitac4f7d3

27 files changed

+71
-71
lines changed

‎git/cmd.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -485,10 +485,10 @@ def readline(self, size=-1):
485485

486486
defreadlines(self,size=-1):
487487
ifself._nbr==self._size:
488-
returnlist()
488+
return[]
489489

490490
# leave all additional logic to our readline method, we just check the size
491-
out=list()
491+
out=[]
492492
nbr=0
493493
whileTrue:
494494
line=self.readline()
@@ -894,7 +894,7 @@ def transform_kwarg(self, name, value, split_single_char_options):
894894

895895
deftransform_kwargs(self,split_single_char_options=True,**kwargs):
896896
"""Transforms Python style kwargs into git command line options."""
897-
args=list()
897+
args=[]
898898
kwargs=OrderedDict(sorted(kwargs.items(),key=lambdax:x[0]))
899899
fork,vinkwargs.items():
900900
ifisinstance(v, (list,tuple)):
@@ -913,7 +913,7 @@ def __unpack_args(cls, arg_list):
913913
return [arg_list.encode(defenc)]
914914
return [str(arg_list)]
915915

916-
outlist=list()
916+
outlist=[]
917917
forarginarg_list:
918918
ifisinstance(arg_list, (list,tuple)):
919919
outlist.extend(cls.__unpack_args(arg))

‎git/diff.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class Diffable(object):
6161
:note:
6262
Subclasses require a repo member as it is the case for Object instances, for practical
6363
reasons we do not derive from Object."""
64-
__slots__=tuple()
64+
__slots__= ()
6565

6666
# standin indicating you want to diff against the index
6767
classIndex(object):
@@ -106,7 +106,7 @@ def diff(self, other=Index, paths=None, create_patch=False, **kwargs):
106106
:note:
107107
On a bare repository, 'other' needs to be provided as Index or as
108108
as Tree/Commit, or a git command error will occur"""
109-
args=list()
109+
args=[]
110110
args.append("--abbrev=40")# we need full shas
111111
args.append("--full-index")# get full index paths, not only filenames
112112

‎git/index/base.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def _set_cache_(self, attr):
121121
ok=True
122122
exceptOSError:
123123
# in new repositories, there may be no index, which means we are empty
124-
self.entries=dict()
124+
self.entries={}
125125
return
126126
finally:
127127
ifnotok:
@@ -324,7 +324,7 @@ def from_tree(cls, repo, *treeish, **kwargs):
324324
iflen(treeish)==0orlen(treeish)>3:
325325
raiseValueError("Please specify between 1 and 3 treeish, got %i"%len(treeish))
326326

327-
arg_list=list()
327+
arg_list=[]
328328
# ignore that working tree and index possibly are out of date
329329
iflen(treeish)>1:
330330
# drop unmerged entries when reading our index and merging
@@ -471,9 +471,9 @@ def unmerged_blobs(self):
471471
are at stage 3 will not have a stage 3 entry.
472472
"""
473473
is_unmerged_blob=lambdat:t[0]!=0
474-
path_map=dict()
474+
path_map={}
475475
forstage,blobinself.iter_blobs(is_unmerged_blob):
476-
path_map.setdefault(blob.path,list()).append((stage,blob))
476+
path_map.setdefault(blob.path,[]).append((stage,blob))
477477
# END for each unmerged blob
478478
forlinmviter(path_map):
479479
l.sort()
@@ -576,8 +576,8 @@ def _to_relative_path(self, path):
576576

577577
def_preprocess_add_items(self,items):
578578
""" Split the items into two lists of path strings and BaseEntries. """
579-
paths=list()
580-
entries=list()
579+
paths=[]
580+
entries=[]
581581

582582
foriteminitems:
583583
ifisinstance(item,string_types):
@@ -610,7 +610,7 @@ def _store_path(self, filepath, fprogress):
610610
@unbare_repo
611611
@git_working_dir
612612
def_entries_for_paths(self,paths,path_rewriter,fprogress,entries):
613-
entries_added=list()
613+
entries_added=[]
614614
ifpath_rewriter:
615615
forpathinpaths:
616616
ifosp.isabs(path):
@@ -742,7 +742,7 @@ def add(self, items, force=True, fprogress=lambda *args: None, path_rewriter=Non
742742
# automatically
743743
# paths can be git-added, for everything else we use git-update-index
744744
paths,entries=self._preprocess_add_items(items)
745-
entries_added=list()
745+
entries_added=[]
746746
# This code needs a working tree, therefore we try not to run it unless required.
747747
# That way, we are OK on a bare repository as well.
748748
# If there are no paths, the rewriter has nothing to do either
@@ -809,7 +809,7 @@ def handle_null_entries(self):
809809
def_items_to_rela_paths(self,items):
810810
"""Returns a list of repo-relative paths from the given items which
811811
may be absolute or relative paths, entries or blobs"""
812-
paths=list()
812+
paths=[]
813813
foriteminitems:
814814
ifisinstance(item, (BaseIndexEntry, (Blob,Submodule))):
815815
paths.append(self._to_relative_path(item.path))
@@ -858,7 +858,7 @@ def remove(self, items, working_tree=False, **kwargs):
858858
been removed effectively.
859859
This is interesting to know in case you have provided a directory or
860860
globs. Paths are relative to the repository. """
861-
args=list()
861+
args=[]
862862
ifnotworking_tree:
863863
args.append("--cached")
864864
args.append("--")
@@ -897,7 +897,7 @@ def move(self, items, skip_errors=False, **kwargs):
897897
898898
:raise ValueError: If only one item was given
899899
GitCommandError: If git could not handle your request"""
900-
args=list()
900+
args=[]
901901
ifskip_errors:
902902
args.append('-k')
903903

@@ -910,7 +910,7 @@ def move(self, items, skip_errors=False, **kwargs):
910910

911911
# first execute rename in dryrun so the command tells us what it actually does
912912
# ( for later output )
913-
out=list()
913+
out=[]
914914
mvlines=self.repo.git.mv(args,paths,**kwargs).splitlines()
915915

916916
# parse result - first 0:n/2 lines are 'checking ', the remaining ones
@@ -1041,9 +1041,9 @@ def handle_stderr(proc, iter_checked_out_files):
10411041
# line contents:
10421042
stderr=stderr.decode(defenc)
10431043
# git-checkout-index: this already exists
1044-
failed_files=list()
1045-
failed_reasons=list()
1046-
unknown_lines=list()
1044+
failed_files=[]
1045+
failed_reasons=[]
1046+
unknown_lines=[]
10471047
endings= (' already exists',' is not in the cache',' does not exist at stage',' is unmerged')
10481048
forlineinstderr.splitlines():
10491049
ifnotline.startswith("git checkout-index: ")andnotline.startswith("git-checkout-index: "):
@@ -1106,7 +1106,7 @@ def handle_stderr(proc, iter_checked_out_files):
11061106
proc=self.repo.git.checkout_index(args,**kwargs)
11071107
# FIXME: Reading from GIL!
11081108
make_exc=lambda:GitCommandError(("git-checkout-index",)+tuple(args),128,proc.stderr.read())
1109-
checked_out_files=list()
1109+
checked_out_files=[]
11101110

11111111
forpathinpaths:
11121112
co_path=to_native_path_linux(self._to_relative_path(path))

‎git/index/fun.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ def read_cache(stream):
187187
* content_sha is a 20 byte sha on all cache file contents"""
188188
version,num_entries=read_header(stream)
189189
count=0
190-
entries=dict()
190+
entries={}
191191

192192
read=stream.read
193193
tell=stream.tell
@@ -236,7 +236,7 @@ def write_tree_from_cache(entries, odb, sl, si=0):
236236
:param sl: slice indicating the range we should process on the entries list
237237
:return: tuple(binsha, list(tree_entry, ...)) a tuple of a sha and a list of
238238
tree entries being a tuple of hexsha, mode, name"""
239-
tree_items=list()
239+
tree_items=[]
240240
tree_items_append=tree_items.append
241241
ci=sl.start
242242
end=sl.stop
@@ -295,7 +295,7 @@ def aggressive_tree_merge(odb, tree_shas):
295295
:param tree_shas: 1, 2 or 3 trees as identified by their binary 20 byte shas
296296
If 1 or two, the entries will effectively correspond to the last given tree
297297
If 3 are given, a 3 way merge is performed"""
298-
out=list()
298+
out=[]
299299
out_append=out.append
300300

301301
# one and two way is the same for us, as we don't have to handle an existing

‎git/objects/blob.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class Blob(base.IndexObject):
2020
file_mode=0o100644
2121
link_mode=0o120000
2222

23-
__slots__=tuple()
23+
__slots__= ()
2424

2525
@property
2626
defmime_type(self):

‎git/objects/commit.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ def create_from_tree(cls, repo, tree, message, parent_commits=None, head=False,
316316
parent_commits= [repo.head.commit]
317317
exceptValueError:
318318
# empty repositories have no head commit
319-
parent_commits=list()
319+
parent_commits=[]
320320
# END handle parent commits
321321
else:
322322
forpinparent_commits:
@@ -450,7 +450,7 @@ def _deserialize(self, stream):
450450
readline=stream.readline
451451
self.tree=Tree(self.repo,hex_to_bin(readline().split()[1]),Tree.tree_id<<12,'')
452452

453-
self.parents=list()
453+
self.parents=[]
454454
next_line=None
455455
whileTrue:
456456
parent_line=readline()

‎git/objects/fun.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def tree_entries_from_data(data):
5050
space_ord=ord(' ')
5151
len_data=len(data)
5252
i=0
53-
out=list()
53+
out=[]
5454
whilei<len_data:
5555
mode=0
5656

@@ -132,18 +132,18 @@ def traverse_trees_recursive(odb, tree_shas, path_prefix):
132132
:param path_prefix: a prefix to be added to the returned paths on this level,
133133
set it '' for the first iteration
134134
:note: The ordering of the returned items will be partially lost"""
135-
trees_data=list()
135+
trees_data=[]
136136
nt=len(tree_shas)
137137
fortree_shaintree_shas:
138138
iftree_shaisNone:
139-
data=list()
139+
data=[]
140140
else:
141141
data=tree_entries_from_data(odb.stream(tree_sha).read())
142142
# END handle muted trees
143143
trees_data.append(data)
144144
# END for each sha to get data for
145145

146-
out=list()
146+
out=[]
147147
out_append=out.append
148148

149149
# find all matching entries and recursively process them together if the match
@@ -193,7 +193,7 @@ def traverse_tree_recursive(odb, tree_sha, path_prefix):
193193
* [1] mode as int
194194
* [2] path relative to the repository
195195
:param path_prefix: prefix to prepend to the front of all returned paths"""
196-
entries=list()
196+
entries=[]
197197
data=tree_entries_from_data(odb.stream(tree_sha).read())
198198

199199
# unpacking/packing is faster than accessing individual items

‎git/objects/submodule/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class UpdateProgress(RemoteProgress):
6060
CLONE,FETCH,UPDWKTREE= [1<<xforxinrange(RemoteProgress._num_op_codes,RemoteProgress._num_op_codes+3)]
6161
_num_op_codes=RemoteProgress._num_op_codes+3
6262

63-
__slots__=tuple()
63+
__slots__= ()
6464

6565

6666
BEGIN=UpdateProgress.BEGIN
@@ -139,7 +139,7 @@ def _get_intermediate_items(self, item):
139139
try:
140140
returntype(self).list_items(item.module())
141141
exceptInvalidGitRepositoryError:
142-
returnlist()
142+
return[]
143143
# END handle intermediate items
144144

145145
@classmethod

‎git/objects/submodule/root.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class RootUpdateProgress(UpdateProgress):
2222
1<<xforxinrange(UpdateProgress._num_op_codes,UpdateProgress._num_op_codes+4)]
2323
_num_op_codes=UpdateProgress._num_op_codes+4
2424

25-
__slots__=tuple()
25+
__slots__= ()
2626

2727

2828
BEGIN=RootUpdateProgress.BEGIN
@@ -38,7 +38,7 @@ class RootModule(Submodule):
3838
"""A (virtual) Root of all submodules in the given repository. It can be used
3939
to more easily traverse all submodules of the master repository"""
4040

41-
__slots__=tuple()
41+
__slots__= ()
4242

4343
k_root_name='__ROOT__'
4444

‎git/objects/tree.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ def __init__(self, repo, binsha, mode=tree_id << 12, path=None):
189189
def_get_intermediate_items(cls,index_object):
190190
ifindex_object.type=="tree":
191191
returntuple(index_object._iter_convert_to_object(index_object._cache))
192-
returntuple()
192+
return ()
193193

194194
def_set_cache_(self,attr):
195195
ifattr=="_cache":

‎git/objects/util.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ def parse_date(string_date):
153153
offset=utctz_to_altz(offset)
154154

155155
# now figure out the date and time portion - split time
156-
date_formats=list()
156+
date_formats=[]
157157
splitter=-1
158158
if','instring_date:
159159
date_formats.append("%a, %d %b %Y")
@@ -248,7 +248,7 @@ class Traversable(object):
248248
into one direction.
249249
Subclasses only need to implement one function.
250250
Instances of the Subclass must be hashable"""
251-
__slots__=tuple()
251+
__slots__= ()
252252

253253
@classmethod
254254
def_get_intermediate_items(cls,item):
@@ -344,7 +344,7 @@ def addToStack(stack, item, branch_first, depth):
344344
classSerializable(object):
345345

346346
"""Defines methods to serialize and deserialize objects from and into a data stream"""
347-
__slots__=tuple()
347+
__slots__= ()
348348

349349
def_serialize(self,stream):
350350
"""Serialize the data of this object into the given data stream

‎git/refs/head.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class HEAD(SymbolicReference):
2020
HEAD reference."""
2121
_HEAD_NAME='HEAD'
2222
_ORIG_HEAD_NAME='ORIG_HEAD'
23-
__slots__=tuple()
23+
__slots__= ()
2424

2525
def__init__(self,repo,path=_HEAD_NAME):
2626
ifpath!=self._HEAD_NAME:

‎git/refs/log.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class RefLogEntry(tuple):
3232

3333
"""Named tuple allowing easy access to the revlog data fields"""
3434
_re_hexsha_only=re.compile('^[0-9A-Fa-f]{40}$')
35-
__slots__=tuple()
35+
__slots__= ()
3636

3737
def__repr__(self):
3838
"""Representation of ourselves in git reflog format"""

‎git/refs/reference.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class Reference(SymbolicReference, LazyMixin, Iterable):
2727

2828
"""Represents a named reference to any object. Subclasses may apply restrictions though,
2929
i.e. Heads can only point to commits."""
30-
__slots__=tuple()
30+
__slots__= ()
3131
_points_to_commits_only=False
3232
_resolve_ref_on_create=True
3333
_common_path_default="refs"

‎git/refs/symbolic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ def delete(cls, repo, path):
444444
pack_file_path=cls._get_packed_refs_path(repo)
445445
try:
446446
withopen(pack_file_path,'rb')asreader:
447-
new_lines=list()
447+
new_lines=[]
448448
made_change=False
449449
dropped_last_line=False
450450
forlineinreader:

‎git/refs/tag.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class TagReference(Reference):
1717
if tagref.tag is not None:
1818
print(tagref.tag.message)"""
1919

20-
__slots__=tuple()
20+
__slots__= ()
2121
_common_path_default="refs/tags"
2222

2323
@property

‎git/remote.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,7 @@ def _get_fetch_info_from_stderr(self, proc, progress):
663663
# lines which are no progress are fetch info lines
664664
# this also waits for the command to finish
665665
# Skip some progress lines that don't provide relevant information
666-
fetch_info_lines=list()
666+
fetch_info_lines=[]
667667
# Basically we want all fetch info lines which appear to be in regular form, and thus have a
668668
# command character. Everything else we ignore,
669669
cmds=set(FetchInfo._flag_map.keys())

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp