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