Skip to content

Commit 2d502db

Browse files
committed
refactor/bug: handle case where netrc returns None.
pyrefly flagged this. Python 3.14 (and 2.7) says authenticators() returns None if there is no matching host. Also the original exceptions IOError and TypeError appear to not be valid in this context. Rewrite to scope FileNotFoundError if .netrc is missing to just the one method call. Handle rest of flow with if/else not exception jump.
1 parent d79e28e commit 2d502db

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

roundup/scripts/roundup_mailgw.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,15 +215,20 @@ def main(argv):
215215

216216
# the source will be a network server, so obtain the credentials to
217217
# use in connecting to the server
218+
authenticator = None
218219
try:
219220
# attempt to obtain credentials from a ~/.netrc file
221+
# returns None if host not found
220222
authenticator = netrc.netrc().authenticators(specification)
223+
except FileNotFoundError:
224+
# FileNotFoundError if no ~/.netrc file
225+
pass
226+
227+
if authenticator:
221228
username = authenticator[0]
222229
password = authenticator[2]
223230
server = specification
224-
# IOError if no ~/.netrc file, TypeError if the hostname
225-
# not found in the ~/.netrc file:
226-
except (IOError, TypeError):
231+
else:
227232
match = re.match(r'((?P<user>[^:]+)(:(?P<pass>.+))?@)?(?P<server>.+)',
228233
specification)
229234
if match:

0 commit comments

Comments
 (0)