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

Commitcfd653a

Browse files
authored
Merge pull request#1295 from Yobmod/main
Add types to refs
2 parentsacbd6ba +600df04 commitcfd653a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+496
-353
lines changed

‎.flake8

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ statistics = True
88
# W293 = Blank line contains whitespace
99
# W504 = Line break after operator
1010
# E704 = multiple statements in one line - used for @override
11-
# TC002 =
11+
# TC002 = move third party import to TYPE_CHECKING
1212
# ANN = flake8-annotations
1313
# TC, TC2 = flake8-type-checking
1414
# D = flake8-docstrings
@@ -19,7 +19,8 @@ enable-extensions = TC, TC2 # only needed for extensions not enabled by default
1919
ignore = E265,E266,E731,E704,
2020
W293, W504,
2121
ANN0 ANN1 ANN2,
22-
TC0, TC1, TC2
22+
TC002,
23+
# TC0, TC1, TC2
2324
# B,
2425
A,
2526
D,

‎README.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -106,19 +106,21 @@ On *Windows*, make sure you have `git-daemon` in your PATH. For MINGW-git, the
106106
exists in`Git\mingw64\libexec\git-core\`; CYGWIN has no daemon, but should get along fine
107107
with MINGW's.
108108

109-
Ensure testing libraries are installed.In the root directory, run:`pip install test-requirements.txt`
110-
Then,
109+
Ensure testing libraries are installed.
110+
In the root directory, run:`pip install -r test-requirements.txt`
111111

112-
To lint, run`flake8`
113-
To typecheck, run`mypy -p git`
114-
To test,`pytest`
112+
To lint, run:`flake8`
115113

116-
Configuration for flake8 is in root/.flake8 file.
117-
Configuration for mypy, pytest, coverage is in root/pyproject.toml.
114+
To typecheck, run:`mypy -p git`
118115

119-
The same linting and testing will also be performed against different supported python versions
120-
upon submitting a pull request (or on each push if you have a fork with a "main" branch).
116+
To test, run:`pytest`
117+
118+
Configuration for flake8 is in the ./.flake8 file.
121119

120+
Configurations for mypy, pytest and coverage.py are in ./pyproject.toml.
121+
122+
The same linting and testing will also be performed against different supported python versions
123+
upon submitting a pull request (or on each push if you have a fork with a "main" branch and actions enabled).
122124

123125

124126
###Contributions

‎git/cmd.py

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
PIPE
1616
)
1717
importsubprocess
18-
importsys
1918
importthreading
2019
fromtextwrapimportdedent
2120

@@ -539,7 +538,7 @@ def __iter__(self) -> 'Git.CatFileContentStream':
539538
returnself
540539

541540
def__next__(self)->bytes:
542-
returnself.next()
541+
returnnext(self)
543542

544543
defnext(self)->bytes:
545544
line=self.readline()
@@ -566,11 +565,11 @@ def __init__(self, working_dir: Union[None, PathLike] = None):
566565
.git directory in case of bare repositories."""
567566
super(Git,self).__init__()
568567
self._working_dir=expand_path(working_dir)
569-
self._git_options= ()# type: Union[List[str], Tuple[str, ...]]
570-
self._persistent_git_options= []# type: List[str]
568+
self._git_options:Union[List[str],Tuple[str, ...]]= ()
569+
self._persistent_git_options:List[str]= []
571570

572571
# Extra environment variables to pass to git commands
573-
self._environment= {}# type: Dict[str, str]
572+
self._environment:Dict[str,str]= {}
574573

575574
# cached command slots
576575
self.cat_file_header=None
@@ -604,35 +603,35 @@ def _set_cache_(self, attr: str) -> None:
604603
process_version=self._call_process('version')# should be as default *args and **kwargs used
605604
version_numbers=process_version.split(' ')[2]
606605

607-
self._version_info=tuple(
608-
int(n)forninversion_numbers.split('.')[:4]ifn.isdigit()
609-
)# type: Tuple[int, int, int, int] # type: ignore
606+
self._version_info=cast(Tuple[int,int,int,int],
607+
tuple(int(n)forninversion_numbers.split('.')[:4]ifn.isdigit())
608+
)
610609
else:
611610
super(Git,self)._set_cache_(attr)
612611
# END handle version info
613612

614-
@property
613+
@property
615614
defworking_dir(self)->Union[None,PathLike]:
616615
""":return: Git directory we are working on"""
617616
returnself._working_dir
618617

619-
@property
618+
@property
620619
defversion_info(self)->Tuple[int,int,int,int]:
621620
"""
622621
:return: tuple(int, int, int, int) tuple with integers representing the major, minor
623622
and additional version numbers as parsed from git version.
624623
This value is generated on demand and is cached"""
625624
returnself._version_info
626625

627-
@overload
626+
@overload
628627
defexecute(self,
629628
command:Union[str,Sequence[Any]],
630629
*,
631630
as_process:Literal[True]
632631
)->'AutoInterrupt':
633632
...
634633

635-
@overload
634+
@overload
636635
defexecute(self,
637636
command:Union[str,Sequence[Any]],
638637
*,
@@ -641,7 +640,7 @@ def execute(self,
641640
)->Union[str,Tuple[int,str,str]]:
642641
...
643642

644-
@overload
643+
@overload
645644
defexecute(self,
646645
command:Union[str,Sequence[Any]],
647646
*,
@@ -650,7 +649,7 @@ def execute(self,
650649
)->Union[bytes,Tuple[int,bytes,str]]:
651650
...
652651

653-
@overload
652+
@overload
654653
defexecute(self,
655654
command:Union[str,Sequence[Any]],
656655
*,
@@ -660,7 +659,7 @@ def execute(self,
660659
)->str:
661660
...
662661

663-
@overload
662+
@overload
664663
defexecute(self,
665664
command:Union[str,Sequence[Any]],
666665
*,
@@ -799,10 +798,7 @@ def execute(self,
799798
ifkill_after_timeout:
800799
raiseGitCommandError(redacted_command,'"kill_after_timeout" feature is not supported on Windows.')
801800
else:
802-
ifsys.version_info[0]>2:
803-
cmd_not_found_exception=FileNotFoundError# NOQA # exists, flake8 unknown @UndefinedVariable
804-
else:
805-
cmd_not_found_exception=OSError
801+
cmd_not_found_exception=FileNotFoundError# NOQA # exists, flake8 unknown @UndefinedVariable
806802
# end handle
807803

808804
stdout_sink= (PIPE
@@ -872,8 +868,8 @@ def _kill_process(pid: int) -> None:
872868

873869
# Wait for the process to return
874870
status=0
875-
stdout_value=b''# type: Union[str, bytes]
876-
stderr_value=b''# type: Union[str, bytes]
871+
stdout_value:Union[str,bytes]=b''
872+
stderr_value:Union[str,bytes]=b''
877873
newline="\n"ifuniversal_newlineselseb"\n"
878874
try:
879875
ifoutput_streamisNone:
@@ -1070,8 +1066,8 @@ def _call_process(self, method: str, *args: Any, **kwargs: Any
10701066
It contains key-values for the following:
10711067
- the :meth:`execute()` kwds, as listed in :var:`execute_kwargs`;
10721068
- "command options" to be converted by :meth:`transform_kwargs()`;
1073-
- the `'insert_kwargs_after'` key which its value must match one of ``*args``,
1074-
and any cmd-options will be appended after the matched arg.
1069+
- the `'insert_kwargs_after'` key which its value must match one of ``*args``
1070+
and any cmd-options will be appended after the matched arg.
10751071
10761072
Examples::
10771073
@@ -1149,7 +1145,7 @@ def _prepare_ref(self, ref: AnyStr) -> bytes:
11491145
# required for command to separate refs on stdin, as bytes
11501146
ifisinstance(ref,bytes):
11511147
# Assume 40 bytes hexsha - bin-to-ascii for some reason returns bytes, not text
1152-
refstr=ref.decode('ascii')# type: str
1148+
refstr:str=ref.decode('ascii')
11531149
elifnotisinstance(ref,str):
11541150
refstr=str(ref)# could be ref-object
11551151
else:

‎git/compat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
# ---------------------------------------------------------------------------
3535

3636

37-
is_win= (os.name=='nt')# type: bool
37+
is_win:bool= (os.name=='nt')
3838
is_posix= (os.name=='posix')
3939
is_darwin= (os.name=='darwin')
4040
defenc=sys.getfilesystemencoding()

‎git/config.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ def get(self, key: str, default: Union[Any, None] = None) -> Union[Any, None]:
208208
defgetall(self,key:str)->Any:
209209
returnsuper(_OMD,self).__getitem__(key)
210210

211-
defitems(self)->List[Tuple[str,Any]]:# type: ignore ## mypy doesn't like overwriting supertype signitures
211+
defitems(self)->List[Tuple[str,Any]]:# type: ignore[override]
212212
"""List of (key, last value for key)."""
213213
return [(k,self[k])forkinself]
214214

@@ -238,7 +238,7 @@ def get_config_path(config_level: Lit_config_levels) -> str:
238238
assert_never(config_level,ValueError(f"Invalid configuration level:{config_level!r}"))
239239

240240

241-
classGitConfigParser(with_metaclass(MetaParserBuilder,cp.RawConfigParser,object)):# type: ignore ## mypy does not understand dynamic class creation # noqa: E501
241+
classGitConfigParser(with_metaclass(MetaParserBuilder,cp.RawConfigParser)):# type: ignore ## mypy does not understand dynamic class creation # noqa: E501
242242

243243
"""Implements specifics required to read git style configuration files.
244244
@@ -322,7 +322,7 @@ def __init__(self, file_or_files: Union[None, PathLike, 'BytesIO', Sequence[Unio
322322
self._is_initialized=False
323323
self._merge_includes=merge_includes
324324
self._repo=repo
325-
self._lock=None# type: Union['LockFile', None]
325+
self._lock:Union['LockFile',None]=None
326326
self._acquire_lock()
327327

328328
def_acquire_lock(self)->None:
@@ -545,13 +545,15 @@ def read(self) -> None:
545545
returnNone
546546
self._is_initialized=True
547547

548-
files_to_read= [""]# type: List[Union[PathLike, IO]] ## just for types until 3.5 dropped
549-
ifisinstance(self._file_or_files, (str)):# replace with PathLike once 3.5 dropped
550-
files_to_read= [self._file_or_files]# for str, as str is a type of Sequence
548+
files_to_read:List[Union[PathLike,IO]]= [""]
549+
ifisinstance(self._file_or_files, (str,os.PathLike)):
550+
# for str or Path, as str is a type of Sequence
551+
files_to_read= [self._file_or_files]
551552
elifnotisinstance(self._file_or_files, (tuple,list,Sequence)):
552-
files_to_read= [self._file_or_files]# for IO or Path
553-
else:
554-
files_to_read=list(self._file_or_files)# for lists or tuples
553+
# could merge with above isinstance once runtime type known
554+
files_to_read= [self._file_or_files]
555+
else:# for lists or tuples
556+
files_to_read=list(self._file_or_files)
555557
# end assure we have a copy of the paths to handle
556558

557559
seen=set(files_to_read)

‎git/db.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
ifTYPE_CHECKING:
1919
fromgit.cmdimportGit
20-
20+
2121

2222
# --------------------------------------------------------
2323

‎git/diff.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ def diff(self, other: Union[Type['Index'], 'Tree', 'Commit', None, str, object]
143143
paths= [paths]
144144

145145
ifhasattr(self,'Has_Repo'):
146-
self.repo:Repo=self.repo
146+
self.repo:'Repo'=self.repo
147147

148148
diff_cmd=self.repo.git.diff
149149
ifotherisself.Index:
@@ -351,13 +351,13 @@ def __hash__(self) -> int:
351351
returnhash(tuple(getattr(self,n)forninself.__slots__))
352352

353353
def__str__(self)->str:
354-
h="%s"# type: str
354+
h:str="%s"
355355
ifself.a_blob:
356356
h%=self.a_blob.path
357357
elifself.b_blob:
358358
h%=self.b_blob.path
359359

360-
msg=''# type: str
360+
msg:str=''
361361
line=None# temp line
362362
line_length=0# line length
363363
forb,ninzip((self.a_blob,self.b_blob), ('lhs','rhs')):
@@ -449,7 +449,7 @@ def _index_from_patch_format(cls, repo: 'Repo', proc: TBD) -> DiffIndex:
449449
:return: git.DiffIndex """
450450

451451
## FIXME: Here SLURPING raw, need to re-phrase header-regexes linewise.
452-
text_list= []# type: List[bytes]
452+
text_list:List[bytes]= []
453453
handle_process_output(proc,text_list.append,None,finalize_process,decode_streams=False)
454454

455455
# for now, we have to bake the stream

‎git/index/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
"""Initialize the index package"""
22
# flake8: noqa
3-
from __future__importabsolute_import
4-
53
from .baseimport*
64
from .typimport*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp