[Patchew-devel] [PATCH] Defines exception handled at get_mbox_with_tags

Caio Carrara posted 1 patch 5 years, 4 months ago
Failed in applying to current master (apply log)
www/views.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[Patchew-devel] [PATCH] Defines exception handled at get_mbox_with_tags
Posted by Caio Carrara 5 years, 4 months ago
When using try..except statement the exception must always be specified
instead of using a bare except. It's a recommendation from PEP8 quoted
below:

A bare except: clause will catch SystemExit and KeyboardInterrupt
exceptions, making it harder to interrupt a program with Control-C, and
can disguise other problems. If you want to catch all exceptions that
signal program errors, use except Exception: (bare except is equivalent
to except BaseException:)[1]

[1] - https://www.python.org/dev/peps/pep-0008/

Signed-off-by: Caio Carrara <ccarrara@redhat.com>
---
 www/views.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/www/views.py b/www/views.py
index 2aae127..89a8127 100644
--- a/www/views.py
+++ b/www/views.py
@@ -297,7 +297,7 @@ def view_mbox(request, project, message_id):
         # patches, quoted-printable is safe and mostly human-readable.
         try:
             container.replace_header('Content-Transfer-Encoding', 'quoted-printable')
-        except:
+        except KeyError:
             msg.add_header('Content-Transfer-Encoding', 'quoted-printable')
         payload = '\n'.join(mbox_with_tags_iter(payload, m.tags))
         payload = quopri.encodestring(payload.encode('utf-8'))
-- 
2.19.2

_______________________________________________
Patchew-devel mailing list
Patchew-devel@redhat.com
https://www.redhat.com/mailman/listinfo/patchew-devel
Re: [Patchew-devel] [PATCH] Defines exception handled at get_mbox_with_tags
Posted by Paolo Bonzini 5 years, 4 months ago
On 28/11/18 19:19, Caio Carrara wrote:
> When using try..except statement the exception must always be specified
> instead of using a bare except. It's a recommendation from PEP8 quoted
> below:
> 
> A bare except: clause will catch SystemExit and KeyboardInterrupt
> exceptions, making it harder to interrupt a program with Control-C, and
> can disguise other problems. If you want to catch all exceptions that
> signal program errors, use except Exception: (bare except is equivalent
> to except BaseException:)[1]
> 
> [1] - https://www.python.org/dev/peps/pep-0008/
> 
> Signed-off-by: Caio Carrara <ccarrara@redhat.com>
> ---
>  www/views.py | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/www/views.py b/www/views.py
> index 2aae127..89a8127 100644
> --- a/www/views.py
> +++ b/www/views.py
> @@ -297,7 +297,7 @@ def view_mbox(request, project, message_id):
>          # patches, quoted-printable is safe and mostly human-readable.
>          try:
>              container.replace_header('Content-Transfer-Encoding', 'quoted-printable')
> -        except:
> +        except KeyError:
>              msg.add_header('Content-Transfer-Encoding', 'quoted-printable')
>          payload = '\n'.join(mbox_with_tags_iter(payload, m.tags))
>          payload = quopri.encodestring(payload.encode('utf-8'))
> 

Queued, thanks.

Paolo

_______________________________________________
Patchew-devel mailing list
Patchew-devel@redhat.com
https://www.redhat.com/mailman/listinfo/patchew-devel