Skip to content

Commit 6e331a0

Browse files
committed
Add types to config.py class SectionConstraint
1 parent efe6833 commit 6e331a0

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

git/config.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -124,40 +124,40 @@ class SectionConstraint(object):
124124
_valid_attrs_ = ("get_value", "set_value", "get", "set", "getint", "getfloat", "getboolean", "has_option",
125125
"remove_section", "remove_option", "options")
126126

127-
def __init__(self, config, section):
127+
def __init__(self, config: cp.ConfigParser, section: str) -> None:
128128
self._config = config
129129
self._section_name = section
130130

131-
def __del__(self):
131+
def __del__(self) -> None:
132132
# Yes, for some reason, we have to call it explicitly for it to work in PY3 !
133133
# Apparently __del__ doesn't get call anymore if refcount becomes 0
134134
# Ridiculous ... .
135135
self._config.release()
136136

137-
def __getattr__(self, attr):
137+
def __getattr__(self, attr: str) -> Any:
138138
if attr in self._valid_attrs_:
139139
return lambda *args, **kwargs: self._call_config(attr, *args, **kwargs)
140140
return super(SectionConstraint, self).__getattribute__(attr)
141141

142-
def _call_config(self, method, *args, **kwargs):
142+
def _call_config(self, method: str, *args: Any, **kwargs: Any) -> Any:
143143
"""Call the configuration at the given method which must take a section name
144144
as first argument"""
145145
return getattr(self._config, method)(self._section_name, *args, **kwargs)
146146

147147
@property
148-
def config(self):
148+
def config(self) -> cp.ConfigParser:
149149
"""return: Configparser instance we constrain"""
150150
return self._config
151151

152-
def release(self):
152+
def release(self) -> None:
153153
"""Equivalent to GitConfigParser.release(), which is called on our underlying parser instance"""
154154
return self._config.release()
155155

156-
def __enter__(self):
156+
def __enter__(self) -> 'SectionConstraint':
157157
self._config.__enter__()
158158
return self
159159

160-
def __exit__(self, exception_type, exception_value, traceback):
160+
def __exit__(self, exception_type: str, exception_value: str, traceback: str) -> None:
161161
self._config.__exit__(exception_type, exception_value, traceback)
162162

163163

@@ -336,10 +336,10 @@ def __enter__(self):
336336
self._acquire_lock()
337337
return self
338338

339-
def __exit__(self, exception_type, exception_value, traceback):
339+
def __exit__(self, exception_type, exception_value, traceback) -> None:
340340
self.release()
341341

342-
def release(self):
342+
def release(self) -> None:
343343
"""Flush changes and release the configuration write lock. This instance must not be used anymore afterwards.
344344
In Python 3, it's required to explicitly release locks and flush changes, as __del__ is not called
345345
deterministically anymore."""

0 commit comments

Comments
 (0)