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

Commit70e67bf

Browse files
authored
Merge pull request#2212 from python-gitlab/jlvillal/config
chore: remove broad Exception catching from `config.py`
2 parents9aecc9e +0abc90b commit70e67bf

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
@@ -17,6 +17,8 @@
1717

1818
HELPER_ATTRIBUTES= ["job_token","http_password","private_token","oauth_token"]
1919

20+
_CONFIG_PARSER_ERRORS= (configparser.NoOptionError,configparser.NoSectionError)
21+
2022

2123
def_resolve_file(filepath:Union[Path,str])->str:
2224
resolved=Path(filepath).resolve(strict=True)
@@ -148,108 +150,102 @@ def _parse_config(self) -> None:
148150
# Value Error means the option exists but isn't a boolean.
149151
# Get as a string instead as it should then be a local path to a
150152
# CA bundle.
151-
try:
152-
self.ssl_verify=_config.get("global","ssl_verify")
153-
exceptException:# pragma: no cover
154-
pass
155-
exceptException:
153+
self.ssl_verify=_config.get("global","ssl_verify")
154+
except_CONFIG_PARSER_ERRORS:
156155
pass
157156
try:
158157
self.ssl_verify=_config.getboolean(self.gitlab_id,"ssl_verify")
159158
exceptValueError:
160159
# Value Error means the option exists but isn't a boolean.
161160
# Get as a string instead as it should then be a local path to a
162161
# CA bundle.
163-
try:
164-
self.ssl_verify=_config.get(self.gitlab_id,"ssl_verify")
165-
exceptException:# pragma: no cover
166-
pass
167-
exceptException:
162+
self.ssl_verify=_config.get(self.gitlab_id,"ssl_verify")
163+
except_CONFIG_PARSER_ERRORS:
168164
pass
169165

170166
try:
171167
self.timeout=_config.getint("global","timeout")
172-
exceptException:
168+
except_CONFIG_PARSER_ERRORS:
173169
pass
174170
try:
175171
self.timeout=_config.getint(self.gitlab_id,"timeout")
176-
exceptException:
172+
except_CONFIG_PARSER_ERRORS:
177173
pass
178174

179175
try:
180176
self.private_token=_config.get(self.gitlab_id,"private_token")
181-
exceptException:
177+
except_CONFIG_PARSER_ERRORS:
182178
pass
183179

184180
try:
185181
self.oauth_token=_config.get(self.gitlab_id,"oauth_token")
186-
exceptException:
182+
except_CONFIG_PARSER_ERRORS:
187183
pass
188184

189185
try:
190186
self.job_token=_config.get(self.gitlab_id,"job_token")
191-
exceptException:
187+
except_CONFIG_PARSER_ERRORS:
192188
pass
193189

194190
try:
195191
self.http_username=_config.get(self.gitlab_id,"http_username")
196192
self.http_password=_config.get(
197193
self.gitlab_id,"http_password"
198194
)# pragma: no cover
199-
exceptException:
195+
except_CONFIG_PARSER_ERRORS:
200196
pass
201197

202198
self._get_values_from_helper()
203199

204200
try:
205201
self.api_version=_config.get("global","api_version")
206-
exceptException:
202+
except_CONFIG_PARSER_ERRORS:
207203
pass
208204
try:
209205
self.api_version=_config.get(self.gitlab_id,"api_version")
210-
exceptException:
206+
except_CONFIG_PARSER_ERRORS:
211207
pass
212208
ifself.api_versionnotin ("4",):
213209
raiseGitlabDataError(f"Unsupported API version:{self.api_version}")
214210

215211
forsectionin ["global",self.gitlab_id]:
216212
try:
217213
self.per_page=_config.getint(section,"per_page")
218-
exceptException:
214+
except_CONFIG_PARSER_ERRORS:
219215
pass
220216
ifself.per_pageisnotNoneandnot0<=self.per_page<=100:
221217
raiseGitlabDataError(f"Unsupported per_page number:{self.per_page}")
222218

223219
try:
224220
self.pagination=_config.get(self.gitlab_id,"pagination")
225-
exceptException:
221+
except_CONFIG_PARSER_ERRORS:
226222
pass
227223

228224
try:
229225
self.order_by=_config.get(self.gitlab_id,"order_by")
230-
exceptException:
226+
except_CONFIG_PARSER_ERRORS:
231227
pass
232228

233229
try:
234230
self.user_agent=_config.get("global","user_agent")
235-
exceptException:
231+
except_CONFIG_PARSER_ERRORS:
236232
pass
237233
try:
238234
self.user_agent=_config.get(self.gitlab_id,"user_agent")
239-
exceptException:
235+
except_CONFIG_PARSER_ERRORS:
240236
pass
241237

242238
try:
243239
self.retry_transient_errors=_config.getboolean(
244240
"global","retry_transient_errors"
245241
)
246-
exceptException:
242+
except_CONFIG_PARSER_ERRORS:
247243
pass
248244
try:
249245
self.retry_transient_errors=_config.getboolean(
250246
self.gitlab_id,"retry_transient_errors"
251247
)
252-
exceptException:
248+
except_CONFIG_PARSER_ERRORS:
253249
pass
254250

255251
def_get_values_from_helper(self)->None:

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp