[PATCH] python: fix get_property error when property doesn't exist

classic Classic list List threaded Threaded
6 messages Options
Vincent A Vincent A
Reply | Threaded
Open this post in threaded view
|

[PATCH] python: fix get_property error when property doesn't exist

In Python bindings, Message.get_property fails with an AttributeError
when trying to fetch a property that doesn't exist.

_______________________________________________
notmuch mailing list
[hidden email]
https://notmuchmail.org/mailman/listinfo/notmuch

0001-python-fix-get_property-error-when-property-doesn-t-.patch (999 bytes) Download Attachment
David Bremner-2 David Bremner-2
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] python: fix get_property error when property doesn't exist

Vincent A <[hidden email]> writes:

> In Python bindings, Message.get_property fails with an AttributeError
> when trying to fetch a property that doesn't exist.

> -        return value.value.decode('utf-8') if value is not None else None
> +        if value is None or value.value is None:
> +            return None
> +        return value.value.decode('utf-8')
>  

Should we be throwing an appropriate exception rather than returning
None? That seems more pythonic to me. In either case we should document
the error handling.

d
_______________________________________________
notmuch mailing list
[hidden email]
https://notmuchmail.org/mailman/listinfo/notmuch
VA VA
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] python: fix get_property error when property doesn't exist

Le 01/02/2019 à 14:45, David Bremner a écrit :
> Should we be throwing an appropriate exception rather than returning
> None? That seems more pythonic to me. In either case we should document
> the error handling.

What would it be? KeyError?
Though, some standard Python methods like dict.get return None in case
the key doesn't exist.
_______________________________________________
notmuch mailing list
[hidden email]
https://notmuchmail.org/mailman/listinfo/notmuch
David Bremner-2 David Bremner-2
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] python: fix get_property error when property doesn't exist

VA <[hidden email]> writes:

> Le 01/02/2019 à 14:45, David Bremner a écrit :
>> Should we be throwing an appropriate exception rather than returning
>> None? That seems more pythonic to me. In either case we should document
>> the error handling.
>
> What would it be? KeyError?
> Though, some standard Python methods like dict.get return None in case
> the key doesn't exist.

Vincent pointed out on IRC that this patch doesn't introduce returning
None here, but just fixes the code that tries to do it. So this patch is
an improvement on the status quo.

d
_______________________________________________
notmuch mailing list
[hidden email]
https://notmuchmail.org/mailman/listinfo/notmuch
Tomi Ollila-2 Tomi Ollila-2
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] python: fix get_property error when property doesn't exist

On Sun, Feb 17 2019, David Bremner wrote:

> VA <[hidden email]> writes:
>
>> Le 01/02/2019 à 14:45, David Bremner a écrit :
>>> Should we be throwing an appropriate exception rather than returning
>>> None? That seems more pythonic to me. In either case we should document
>>> the error handling.
>>
>> What would it be? KeyError?
>> Though, some standard Python methods like dict.get return None in case
>> the key doesn't exist.
>
> Vincent pointed out on IRC that this patch doesn't introduce returning
> None here, but just fixes the code that tries to do it. So this patch is
> an improvement on the status quo.

indeed. +1

Tomi


>
> d
> _______________________________________________
> notmuch mailing list
> [hidden email]
> https://notmuchmail.org/mailman/listinfo/notmuch
_______________________________________________
notmuch mailing list
[hidden email]
https://notmuchmail.org/mailman/listinfo/notmuch
David Bremner-2 David Bremner-2
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] python: fix get_property error when property doesn't exist

In reply to this post by Vincent A
Vincent A <[hidden email]> writes:

> In Python bindings, Message.get_property fails with an AttributeError
> when trying to fetch a property that doesn't exist.
> From d712832ba982085975c27b23bb502af82e638b39 Mon Sep 17 00:00:00 2001
> From: hydrargyrum <[hidden email]>
> Date: Sun, 6 Jan 2019 16:08:55 +0100
> Subject: [PATCH] python: fix get_property error when property doesn't exist
>

pushed, thanks.

BTW, if possible please use git send-email rather than attachements, as
it simplifies the review process. You can still add (non-commit message)
commentary after the --- by passing --annotate.

d



_______________________________________________
notmuch mailing list
[hidden email]
https://notmuchmail.org/mailman/listinfo/notmuch