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

Commitd6e7369

Browse files
committed
Add final types to config.py
1 parent35231db commitd6e7369

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

‎git/config.py‎

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,15 @@
4040
fromioimportBytesIO
4141

4242
T_ConfigParser=TypeVar('T_ConfigParser',bound='GitConfigParser')
43+
T_OMD_value=TypeVar('T_OMD_value',str,bytes,int,float,bool)
4344

4445
ifsys.version_info[:3]< (3,7,2):
4546
# typing.Ordereddict not added until py 3.7.2
4647
fromcollectionsimportOrderedDict# type: ignore # until 3.6 dropped
4748
OrderedDict_OMD=OrderedDict# type: ignore # until 3.6 dropped
4849
else:
4950
fromtypingimportOrderedDict# type: ignore # until 3.6 dropped
50-
OrderedDict_OMD=OrderedDict[str,List[_T]]# type: ignore[assignment, misc]
51+
OrderedDict_OMD=OrderedDict[str,List[T_OMD_value]]# type: ignore[assignment, misc]
5152

5253
# -------------------------------------------------------------
5354

@@ -97,23 +98,23 @@ def __new__(cls, name: str, bases: TBD, clsdict: Dict[str, Any]) -> TBD:
9798
returnnew_type
9899

99100

100-
defneeds_values(func:Callable)->Callable:
101+
defneeds_values(func:Callable[...,_T])->Callable[...,_T]:
101102
"""Returns method assuring we read values (on demand) before we try to access them"""
102103

103104
@wraps(func)
104-
defassure_data_present(self,*args:Any,**kwargs:Any)->Any:
105+
defassure_data_present(self:GitConfigParser,*args:Any,**kwargs:Any)->_T:
105106
self.read()
106107
returnfunc(self,*args,**kwargs)
107108
# END wrapper method
108109
returnassure_data_present
109110

110111

111-
defset_dirty_and_flush_changes(non_const_func:Callable)->Callable:
112+
defset_dirty_and_flush_changes(non_const_func:Callable[...,_T])->Callable[...,_T]:
112113
"""Return method that checks whether given non constant function may be called.
113114
If so, the instance will be set dirty.
114115
Additionally, we flush the changes right to disk"""
115116

116-
defflush_changes(self,*args:Any,**kwargs:Any)->Any:
117+
defflush_changes(self:GitConfigParser,*args:Any,**kwargs:Any)->_T:
117118
rval=non_const_func(self,*args,**kwargs)
118119
self._dirty=True
119120
self.write()
@@ -356,7 +357,7 @@ def __enter__(self) -> 'GitConfigParser':
356357
self._acquire_lock()
357358
returnself
358359

359-
def__exit__(self,exception_type,exception_value,traceback)->None:
360+
def__exit__(self,*args:Any)->None:
360361
self.release()
361362

362363
defrelease(self)->None:
@@ -613,12 +614,15 @@ def read(self) -> None: # type: ignore[override]
613614
def_write(self,fp:IO)->None:
614615
"""Write an .ini-format representation of the configuration state in
615616
git compatible format"""
616-
defwrite_section(name,section_dict):
617+
defwrite_section(name:str,section_dict:_OMD)->None:
617618
fp.write(("[%s]\n"%name).encode(defenc))
619+
620+
values:Sequence[Union[str,bytes,int,float,bool]]
618621
for (key,values)insection_dict.items_all():
619622
ifkey=="__name__":
620623
continue
621624

625+
v:Union[str,bytes,int,float,bool]
622626
forvinvalues:
623627
fp.write(("\t%s = %s\n"% (key,self._value_to_string(v).replace('\n','\n\t'))).encode(defenc))
624628
# END if key is not __name__

‎git/util.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ def expand_path(p: Union[None, PathLike], expand_vars: bool = True) -> Optional[
408408
returnNone
409409

410410

411-
defremove_password_if_present(cmdline):
411+
defremove_password_if_present(cmdline:Sequence[str])->List[str]:
412412
"""
413413
Parse any command line argument and if on of the element is an URL with a
414414
password, replace it by stars (in-place).
@@ -1033,7 +1033,7 @@ def __delitem__(self, index: Union[SupportsIndex, int, slice, str]) -> None:
10331033

10341034
classIterableClassWatcher(type):
10351035
""" Metaclass that watches """
1036-
def__init__(cls,name,bases,clsdict):
1036+
def__init__(cls,name:str,bases:List,clsdict:Dict)->None:
10371037
forbaseinbases:
10381038
iftype(base)==IterableClassWatcher:
10391039
warnings.warn(f"GitPython Iterable subclassed by{name}. "
@@ -1052,7 +1052,7 @@ class Iterable(metaclass=IterableClassWatcher):
10521052
_id_attribute_="attribute that most suitably identifies your instance"
10531053

10541054
@classmethod
1055-
deflist_items(cls,repo,*args,**kwargs):
1055+
deflist_items(cls,repo:'Repo',*args:Any,**kwargs:Any)->Any:
10561056
"""
10571057
Deprecated, use IterableObj instead.
10581058
Find all items of this type - subclasses can specify args and kwargs differently.
@@ -1062,7 +1062,7 @@ def list_items(cls, repo, *args, **kwargs):
10621062
:note: Favor the iter_items method as it will
10631063
10641064
:return:list(Item,...) list of item instances"""
1065-
out_list=IterableList(cls._id_attribute_)
1065+
out_list:Any=IterableList(cls._id_attribute_)
10661066
out_list.extend(cls.iter_items(repo,*args,**kwargs))
10671067
returnout_list
10681068

‎pyproject.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ filterwarnings = 'ignore::DeprecationWarning'
1919
# filterwarnings ignore::WarningType # ignores those warnings
2020

2121
[tool.mypy]
22-
#disallow_untyped_defs = true
22+
#disallow_untyped_defs = true
2323
no_implicit_optional =true
2424
warn_redundant_casts =true
2525
# warn_unused_ignores = True

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2026 Movatter.jp