Merge pull request #4385 from jdufresne/try-block

Limit try block to code expected to raise an exception
This commit is contained in:
Hugo van Kemenade 2020-01-26 20:04:39 +02:00 committed by GitHub
commit 892aec306b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -401,15 +401,17 @@ def _getdecoder(mode, decoder_name, args, extra=()):
try: try:
decoder = DECODERS[decoder_name] decoder = DECODERS[decoder_name]
return decoder(mode, *args + extra)
except KeyError: except KeyError:
pass pass
else:
return decoder(mode, *args + extra)
try: try:
# get decoder # get decoder
decoder = getattr(core, decoder_name + "_decoder") decoder = getattr(core, decoder_name + "_decoder")
return decoder(mode, *args + extra)
except AttributeError: except AttributeError:
raise OSError("decoder %s not available" % decoder_name) raise OSError("decoder %s not available" % decoder_name)
return decoder(mode, *args + extra)
def _getencoder(mode, encoder_name, args, extra=()): def _getencoder(mode, encoder_name, args, extra=()):
@ -422,15 +424,17 @@ def _getencoder(mode, encoder_name, args, extra=()):
try: try:
encoder = ENCODERS[encoder_name] encoder = ENCODERS[encoder_name]
return encoder(mode, *args + extra)
except KeyError: except KeyError:
pass pass
else:
return encoder(mode, *args + extra)
try: try:
# get encoder # get encoder
encoder = getattr(core, encoder_name + "_encoder") encoder = getattr(core, encoder_name + "_encoder")
return encoder(mode, *args + extra)
except AttributeError: except AttributeError:
raise OSError("encoder %s not available" % encoder_name) raise OSError("encoder %s not available" % encoder_name)
return encoder(mode, *args + extra)
# -------------------------------------------------------------------- # --------------------------------------------------------------------