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

Commit39e2dff

Browse files
committed
Don't return with operand when conceptually void
This changes `return None` to `return` where it appears infunctions that are "conceptually void," i.e. cases where a functionalways returns None, its purpose is never to provide a return valueto the caller, and it would be a bug (or at least confusing style)to use the return value or have the call as a subexpression.This is already the prevailing style, so this is a consistencyimprovement, as well as improving clarity by avoiding giving theimpression that "None" is significant in those cases.Of course, functions that sometimes return values other than Nonedo not have "return None" replaced with a bare "return" statement.Those are left alone (when they return None, it means something).For the most part this is straightforward, but:- The handle_stderr local function in IndexFile.checkout is also slightly further refactored to better express what the early return is doing.- The "None" operand is removed as usual in GitConfigParser.read, even though a superclass has a same-named method with a return type that is not None. Usually when this happens, the superclass method returns something like Optional[Something], and it is a case of return type covariance, in which case the None operands should still be written. Here, however, the overriding method does not intend to be an override: it has an incompatible signature and cannot be called as if it were the superclass method, nor is its return type compatible.- The "None" operand is *retained* in git.cmd.handle_process_output even though the return type is annotated as None, because the function also returns the expression `finalizer(process)`. The argument `finalizer` is itself annotated to return None, but it looks like the intent may be to play along with the strange case that `finalizer` returns a non-None value, and forward it.
1 parentb8ee9be commit39e2dff

File tree

7 files changed

+16
-15
lines changed

7 files changed

+16
-15
lines changed

‎git/cmd.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -528,13 +528,13 @@ def _terminate(self) -> None:
528528
try:
529529
ifproc.poll()isnotNone:
530530
self.status=self._status_code_if_terminateorproc.poll()
531-
returnNone
531+
return
532532
exceptOSErrorasex:
533533
log.info("Ignored error after process had died: %r",ex)
534534

535535
# It can be that nothing really exists anymore...
536536
ifosisNoneorgetattr(os,"kill",None)isNone:
537-
returnNone
537+
return
538538

539539
# Try to kill it.
540540
try:

‎git/config.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,8 @@ def __setitem__(self, key: str, value: _T) -> None:
203203
defadd(self,key:str,value:Any)->None:
204204
ifkeynotinself:
205205
super().__setitem__(key, [value])
206-
returnNone
206+
return
207+
207208
super().__getitem__(key).append(value)
208209

209210
defsetall(self,key:str,values:List[_T])->None:
@@ -579,7 +580,7 @@ def read(self) -> None: # type: ignore[override]
579580
:raise IOError: If a file cannot be handled
580581
"""
581582
ifself._is_initialized:
582-
returnNone
583+
return
583584
self._is_initialized=True
584585

585586
files_to_read:List[Union[PathLike,IO]]= [""]
@@ -697,7 +698,7 @@ def write(self) -> None:
697698
a file lock"""
698699
self._assure_writable("write")
699700
ifnotself._dirty:
700-
returnNone
701+
return
701702

702703
ifisinstance(self._file_or_files, (list,tuple)):
703704
raiseAssertionError(
@@ -711,7 +712,7 @@ def write(self) -> None:
711712
"Skipping write-back of configuration file as include files were merged in."
712713
+"Set merge_includes=False to prevent this."
713714
)
714-
returnNone
715+
return
715716
# END stop if we have include files
716717

717718
fp=self._file_or_files

‎git/index/base.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def _set_cache_(self, attr: str) -> None:
166166
exceptOSError:
167167
# In new repositories, there may be no index, which means we are empty.
168168
self.entries:Dict[Tuple[PathLike,StageType],IndexEntry]= {}
169-
returnNone
169+
return
170170
# END exception handling
171171

172172
try:
@@ -1210,9 +1210,9 @@ def checkout(
12101210
defhandle_stderr(proc:"Popen[bytes]",iter_checked_out_files:Iterable[PathLike])->None:
12111211
stderr_IO=proc.stderr
12121212
ifnotstderr_IO:
1213-
returnNone# Return early if stderr empty.
1214-
else:
1215-
stderr_bytes=stderr_IO.read()
1213+
return# Return early if stderr empty.
1214+
1215+
stderr_bytes=stderr_IO.read()
12161216
# line contents:
12171217
stderr=stderr_bytes.decode(defenc)
12181218
# git-checkout-index: this already exists

‎git/index/fun.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def run_commit_hook(name: str, index: "IndexFile", *args: str) -> None:
8383
"""
8484
hp=hook_path(name,index.repo.git_dir)
8585
ifnotos.access(hp,os.X_OK):
86-
returnNone
86+
return
8787

8888
env=os.environ.copy()
8989
env["GIT_INDEX_FILE"]=safe_decode(str(index.path))

‎git/objects/tree.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def git_cmp(t1: TreeCacheTup, t2: TreeCacheTup) -> int:
6868

6969
defmerge_sort(a:List[TreeCacheTup],cmp:Callable[[TreeCacheTup,TreeCacheTup],int])->None:
7070
iflen(a)<2:
71-
returnNone
71+
return
7272

7373
mid=len(a)//2
7474
lefthalf=a[:mid]

‎git/objects/util.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -500,8 +500,8 @@ def addToStack(
500500
depth:int,
501501
)->None:
502502
lst=self._get_intermediate_items(item)
503-
ifnotlst:#empty list
504-
returnNone
503+
ifnotlst:#Empty list
504+
return
505505
ifbranch_first:
506506
stack.extendleft(TraverseNT(depth,i,src_item)foriinlst)
507507
else:

‎git/util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ def _parse_progress_line(self, line: AnyStr) -> None:
644644
self.line_dropped(line_str)
645645
# Note: Don't add this line to the other lines, as we have to silently
646646
# drop it.
647-
returnNone
647+
return
648648
# END handle op code
649649

650650
# Figure out stage.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp