* [PATCH] python: fix get_property error when property doesn't exist
@ 2019-01-27 8:40 Vincent A
2019-02-01 13:45 ` David Bremner
2019-02-21 11:23 ` David Bremner
0 siblings, 2 replies; 6+ messages in thread
From: Vincent A @ 2019-01-27 8:40 UTC (permalink / raw)
To: notmuch
[-- Attachment #1: Type: text/plain, Size: 123 bytes --]
In Python bindings, Message.get_property fails with an AttributeError
when trying to fetch a property that doesn't exist.
[-- Attachment #2: 0001-python-fix-get_property-error-when-property-doesn-t-.patch --]
[-- Type: text/x-patch, Size: 972 bytes --]
From d712832ba982085975c27b23bb502af82e638b39 Mon Sep 17 00:00:00 2001
From: hydrargyrum <dev@indigo.re>
Date: Sun, 6 Jan 2019 16:08:55 +0100
Subject: [PATCH] python: fix get_property error when property doesn't exist
---
bindings/python/notmuch/message.py | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/bindings/python/notmuch/message.py b/bindings/python/notmuch/message.py
index de0fb415..6e32b5f7 100644
--- a/bindings/python/notmuch/message.py
+++ b/bindings/python/notmuch/message.py
@@ -482,7 +482,9 @@ class Message(Python3StringMixIn):
if status != 0:
raise NotmuchError(status)
- 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')
def get_properties(self, prop="", exact=False):
""" Get the properties of the message, returning a generator of
--
2.20.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] python: fix get_property error when property doesn't exist
2019-01-27 8:40 [PATCH] python: fix get_property error when property doesn't exist Vincent A
@ 2019-02-01 13:45 ` David Bremner
2019-02-06 19:24 ` VA
2019-02-21 11:23 ` David Bremner
1 sibling, 1 reply; 6+ messages in thread
From: David Bremner @ 2019-02-01 13:45 UTC (permalink / raw)
To: Vincent A, notmuch
Vincent A <dev@indigo.re> 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
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] python: fix get_property error when property doesn't exist
2019-02-01 13:45 ` David Bremner
@ 2019-02-06 19:24 ` VA
2019-02-17 11:19 ` David Bremner
0 siblings, 1 reply; 6+ messages in thread
From: VA @ 2019-02-06 19:24 UTC (permalink / raw)
To: David Bremner, notmuch
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.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] python: fix get_property error when property doesn't exist
2019-02-06 19:24 ` VA
@ 2019-02-17 11:19 ` David Bremner
2019-02-18 19:29 ` Tomi Ollila
0 siblings, 1 reply; 6+ messages in thread
From: David Bremner @ 2019-02-17 11:19 UTC (permalink / raw)
To: VA, notmuch
VA <dev+notmuch@indigo.re> 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
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] python: fix get_property error when property doesn't exist
2019-02-17 11:19 ` David Bremner
@ 2019-02-18 19:29 ` Tomi Ollila
0 siblings, 0 replies; 6+ messages in thread
From: Tomi Ollila @ 2019-02-18 19:29 UTC (permalink / raw)
To: David Bremner, VA, notmuch
On Sun, Feb 17 2019, David Bremner wrote:
> VA <dev+notmuch@indigo.re> 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
> notmuch@notmuchmail.org
> https://notmuchmail.org/mailman/listinfo/notmuch
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] python: fix get_property error when property doesn't exist
2019-01-27 8:40 [PATCH] python: fix get_property error when property doesn't exist Vincent A
2019-02-01 13:45 ` David Bremner
@ 2019-02-21 11:23 ` David Bremner
1 sibling, 0 replies; 6+ messages in thread
From: David Bremner @ 2019-02-21 11:23 UTC (permalink / raw)
To: Vincent A, notmuch
Vincent A <dev@indigo.re> 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 <dev@indigo.re>
> 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
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2019-02-21 11:23 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-01-27 8:40 [PATCH] python: fix get_property error when property doesn't exist Vincent A
2019-02-01 13:45 ` David Bremner
2019-02-06 19:24 ` VA
2019-02-17 11:19 ` David Bremner
2019-02-18 19:29 ` Tomi Ollila
2019-02-21 11:23 ` David Bremner
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).