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

Commit5d7e55b

Browse files
committed
Add return-type annotation on __init__ methods
Although sometimes found unintuitive, the reutrn type of a class's__init__ method is best annotated as None, as in other functionsthat return implicitly or by operand-less return statements.Note that this is only a minor improvement, effectively just astyle fix, because mypy treats __init__ specially and, *when atleast one parameter is annotated*, its return type is implicitlyNone rather than implicitly Any like other functions. All the__init__ methods modified here did already have one or moreannotated parameters.However, having __init__ methods without the return type makes iteasier to introduce a bug where an __init__ method with noparameters besides self -- which itself should almost always beunannotated and is properly inferred -- is written and the returnannotation needed to get mypy to regard it as statically typed,so it checks it at all, is omitted. (It is also inelegant whenone considers the meaning of __init__ and the distinction betweenit and __new__.)This commit does not add any return type annotations to functionsin the test suite, since the test suite doesn't currently usestatic typing.Further reading:-https://peps.python.org/pep-0484/#the-meaning-of-annotations-python/mypy#604-#1755 (comment)
1 parente984bfe commit5d7e55b

File tree

7 files changed

+7
-7
lines changed

7 files changed

+7
-7
lines changed

‎git/cmd.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -846,7 +846,7 @@ def __del__(self) -> None:
846846
self._stream.read(bytes_left+1)
847847
# END handle incomplete read
848848

849-
def__init__(self,working_dir:Union[None,PathLike]=None):
849+
def__init__(self,working_dir:Union[None,PathLike]=None)->None:
850850
"""Initialize this instance with:
851851
852852
:param working_dir:

‎git/objects/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class Object(LazyMixin):
5555

5656
type:Union[Lit_commit_ish,None]=None
5757

58-
def__init__(self,repo:"Repo",binsha:bytes):
58+
def__init__(self,repo:"Repo",binsha:bytes)->None:
5959
"""Initialize an object by identifying it by its binary sha.
6060
6161
All keyword arguments will be set on demand if ``None``.

‎git/objects/submodule/root.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class RootModule(Submodule):
5656

5757
k_root_name="__ROOT__"
5858

59-
def__init__(self,repo:"Repo"):
59+
def__init__(self,repo:"Repo")->None:
6060
# repo, binsha, mode=None, path=None, name = None, parent_commit=None, url=None, ref=None)
6161
super().__init__(
6262
repo,

‎git/refs/head.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class HEAD(SymbolicReference):
4444

4545
__slots__= ()
4646

47-
def__init__(self,repo:"Repo",path:PathLike=_HEAD_NAME):
47+
def__init__(self,repo:"Repo",path:PathLike=_HEAD_NAME)->None:
4848
ifpath!=self._HEAD_NAME:
4949
raiseValueError("HEAD instance must point to %r, got %r"% (self._HEAD_NAME,path))
5050
super().__init__(repo,path)

‎git/refs/log.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def __new__(cls, filepath: Union[PathLike, None] = None) -> "RefLog":
164164
inst=super().__new__(cls)
165165
returninst
166166

167-
def__init__(self,filepath:Union[PathLike,None]=None):
167+
def__init__(self,filepath:Union[PathLike,None]=None)->None:
168168
"""Initialize this instance with an optional filepath, from which we will
169169
initialize our data. The path is also used to write changes back using the
170170
:meth:`write` method."""

‎git/refs/symbolic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class SymbolicReference:
7474
_remote_common_path_default="refs/remotes"
7575
_id_attribute_="name"
7676

77-
def__init__(self,repo:"Repo",path:PathLike,check_path:bool=False):
77+
def__init__(self,repo:"Repo",path:PathLike,check_path:bool=False)->None:
7878
self.repo=repo
7979
self.path=path
8080

‎git/util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -917,7 +917,7 @@ class Stats:
917917

918918
__slots__= ("total","files")
919919

920-
def__init__(self,total:Total_TD,files:Dict[PathLike,Files_TD]):
920+
def__init__(self,total:Total_TD,files:Dict[PathLike,Files_TD])->None:
921921
self.total=total
922922
self.files=files
923923

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp