[PATCH] test: Make gen-threads work with python3
Tomi Ollila
tomi.ollila at iki.fi
Sat Nov 1 01:08:26 PDT 2014
On Fri, Oct 31 2014, "W. Trevor King" <wking at tremily.us> wrote:
> On Fri, Oct 31, 2014 at 01:33:25PM -0400, Jesse Rosenthal wrote:
>> We instead initalize the dictionary using the dict comprehension and
>> then update it with the values from the tree. This will work with
>> both python2 and python3.
>
> Dict comprehensions are new in 2.7 [1,2], so this drops support for
> systems where ‘python’ means ‘python2.6’. Personally, I'm fine with
> that, but I thought I'd point it out in case 2.6 users wanted to push
> back ;).
Thanks Trevor. The original changed line:
- ntree = dict(tree, **{child: to_expand[0] for child in children})
is already incompatible with python 2.6, so this doesn't change the current
status quo there.
The above changed to
+ ntree = dict(tree, **dict((child, to_expand[0]) for child in children))
works in Python 2.6 (if anyone interested), and it looks the change in this
patch is not difficult to make work in python 2.6 in case anyone
desires to do so...
Although I have ready-made patch to make the former code work in python 2.6
I've thought that maybe it is just unnecessary burden to support python 2.6
there -- so that people can concentrate on improving tests instead...
Therefore, +1 for this patch, provided that it works as expected.
Tomi
>
>> diff --git a/test/gen-threads.py b/test/gen-threads.py
>> index 9fbb847..70fb1f6 100644
>> --- a/test/gen-threads.py
>> +++ b/test/gen-threads.py
>> @@ -2,7 +2,6 @@
>> # argv[1]. Each output line is a thread structure, where the n'th
>> # field is either a number giving the parent of message n or "None"
>> # for the root.
>> -
>> import sys
>
> Why remove this blank line?
>
>> from itertools import chain, combinations
>>
>> @@ -28,6 +27,7 @@ while queue:
>> else:
>> # Expand node to_expand[0] with each possible set of children
>> for children in subsets(free):
>> - ntree = dict(tree, **{child: to_expand[0] for child in children})
>> + ntree = {child: to_expand[0] for child in children}
>> + ntree.update(tree)
>
> This looks good to me.
>
> Cheers,
> Trevor
>
> [1]: https://docs.python.org/3/whatsnew/2.7.html#other-language-changes
> [2]: http://legacy.python.org/dev/peps/pep-0274/
>
> --
> This email may be signed or encrypted with GnuPG (http://www.gnupg.org).
> For more information, see http://en.wikipedia.org/wiki/Pretty_Good_Privacy
> _______________________________________________
> notmuch mailing list
> notmuch at notmuchmail.org
> http://notmuchmail.org/mailman/listinfo/notmuch
More information about the notmuch
mailing list