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

Commit17dc79d

Browse files
chore: remove broad Exception catching fromconfig.py
Change "except Exception:" catching to more granular exceptions.A step in enabling the "broad-except" check in pylint.
1 parent50822f8 commit17dc79d

File tree

1 file changed

+21
-25
lines changed

1 file changed

+21
-25
lines changed

‎gitlab/config.py

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434

3535
HELPER_ATTRIBUTES= ["job_token","http_password","private_token","oauth_token"]
3636

37+
_CONFIG_PARSER_ERRORS= (configparser.NoOptionError,configparser.NoSectionError)
38+
3739

3840
def_resolve_file(filepath:Union[Path,str])->str:
3941
resolved=Path(filepath).resolve(strict=True)
@@ -165,108 +167,102 @@ def _parse_config(self) -> None:
165167
# Value Error means the option exists but isn't a boolean.
166168
# Get as a string instead as it should then be a local path to a
167169
# CA bundle.
168-
try:
169-
self.ssl_verify=_config.get("global","ssl_verify")
170-
exceptException:# pragma: no cover
171-
pass
172-
exceptException:
170+
self.ssl_verify=_config.get("global","ssl_verify")
171+
except_CONFIG_PARSER_ERRORS:
173172
pass
174173
try:
175174
self.ssl_verify=_config.getboolean(self.gitlab_id,"ssl_verify")
176175
exceptValueError:
177176
# Value Error means the option exists but isn't a boolean.
178177
# Get as a string instead as it should then be a local path to a
179178
# CA bundle.
180-
try:
181-
self.ssl_verify=_config.get(self.gitlab_id,"ssl_verify")
182-
exceptException:# pragma: no cover
183-
pass
184-
exceptException:
179+
self.ssl_verify=_config.get(self.gitlab_id,"ssl_verify")
180+
except_CONFIG_PARSER_ERRORS:
185181
pass
186182

187183
try:
188184
self.timeout=_config.getint("global","timeout")
189-
exceptException:
185+
except_CONFIG_PARSER_ERRORS:
190186
pass
191187
try:
192188
self.timeout=_config.getint(self.gitlab_id,"timeout")
193-
exceptException:
189+
except_CONFIG_PARSER_ERRORS:
194190
pass
195191

196192
try:
197193
self.private_token=_config.get(self.gitlab_id,"private_token")
198-
exceptException:
194+
except_CONFIG_PARSER_ERRORS:
199195
pass
200196

201197
try:
202198
self.oauth_token=_config.get(self.gitlab_id,"oauth_token")
203-
exceptException:
199+
except_CONFIG_PARSER_ERRORS:
204200
pass
205201

206202
try:
207203
self.job_token=_config.get(self.gitlab_id,"job_token")
208-
exceptException:
204+
except_CONFIG_PARSER_ERRORS:
209205
pass
210206

211207
try:
212208
self.http_username=_config.get(self.gitlab_id,"http_username")
213209
self.http_password=_config.get(
214210
self.gitlab_id,"http_password"
215211
)# pragma: no cover
216-
exceptException:
212+
except_CONFIG_PARSER_ERRORS:
217213
pass
218214

219215
self._get_values_from_helper()
220216

221217
try:
222218
self.api_version=_config.get("global","api_version")
223-
exceptException:
219+
except_CONFIG_PARSER_ERRORS:
224220
pass
225221
try:
226222
self.api_version=_config.get(self.gitlab_id,"api_version")
227-
exceptException:
223+
except_CONFIG_PARSER_ERRORS:
228224
pass
229225
ifself.api_versionnotin ("4",):
230226
raiseGitlabDataError(f"Unsupported API version:{self.api_version}")
231227

232228
forsectionin ["global",self.gitlab_id]:
233229
try:
234230
self.per_page=_config.getint(section,"per_page")
235-
exceptException:
231+
except_CONFIG_PARSER_ERRORS:
236232
pass
237233
ifself.per_pageisnotNoneandnot0<=self.per_page<=100:
238234
raiseGitlabDataError(f"Unsupported per_page number:{self.per_page}")
239235

240236
try:
241237
self.pagination=_config.get(self.gitlab_id,"pagination")
242-
exceptException:
238+
except_CONFIG_PARSER_ERRORS:
243239
pass
244240

245241
try:
246242
self.order_by=_config.get(self.gitlab_id,"order_by")
247-
exceptException:
243+
except_CONFIG_PARSER_ERRORS:
248244
pass
249245

250246
try:
251247
self.user_agent=_config.get("global","user_agent")
252-
exceptException:
248+
except_CONFIG_PARSER_ERRORS:
253249
pass
254250
try:
255251
self.user_agent=_config.get(self.gitlab_id,"user_agent")
256-
exceptException:
252+
except_CONFIG_PARSER_ERRORS:
257253
pass
258254

259255
try:
260256
self.retry_transient_errors=_config.getboolean(
261257
"global","retry_transient_errors"
262258
)
263-
exceptException:
259+
except_CONFIG_PARSER_ERRORS:
264260
pass
265261
try:
266262
self.retry_transient_errors=_config.getboolean(
267263
self.gitlab_id,"retry_transient_errors"
268264
)
269-
exceptException:
265+
except_CONFIG_PARSER_ERRORS:
270266
pass
271267

272268
def_get_values_from_helper(self)->None:

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp