unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH] test: Make gen-threads work with python3
@ 2014-10-31 17:33 Jesse Rosenthal
  2014-10-31 17:41 ` W. Trevor King
  2014-11-02 19:03 ` David Bremner
  0 siblings, 2 replies; 6+ messages in thread
From: Jesse Rosenthal @ 2014-10-31 17:33 UTC (permalink / raw)
  To: notmuch

python3 doesn't allow dictionaries to be initialized with non-string
keywords. This presents problems on systems in which "python" means
"python3". 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.
---
 test/gen-threads.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

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
 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)
             nfree = free.difference(children)
             queue.append((ntree, nfree, to_expand[1:] + tuple(children)))
-- 
2.1.2

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] test: Make gen-threads work with python3
  2014-10-31 17:33 [PATCH] test: Make gen-threads work with python3 Jesse Rosenthal
@ 2014-10-31 17:41 ` W. Trevor King
  2014-10-31 18:04   ` Jesse Rosenthal
  2014-11-01  8:08   ` Tomi Ollila
  2014-11-02 19:03 ` David Bremner
  1 sibling, 2 replies; 6+ messages in thread
From: W. Trevor King @ 2014-10-31 17:41 UTC (permalink / raw)
  To: Jesse Rosenthal; +Cc: notmuch

[-- Attachment #1: Type: text/plain, Size: 1580 bytes --]

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 ;).

> 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

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] test: Make gen-threads work with python3
  2014-10-31 17:41 ` W. Trevor King
@ 2014-10-31 18:04   ` Jesse Rosenthal
  2014-10-31 18:18     ` W. Trevor King
  2014-11-01  8:08   ` Tomi Ollila
  1 sibling, 1 reply; 6+ messages in thread
From: Jesse Rosenthal @ 2014-10-31 18:04 UTC (permalink / raw)
  To: W. Trevor King; +Cc: notmuch

"W. Trevor King" <wking@tremily.us> writes:

> 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 ;).

The comprehension was already in the previous version, so I figured that
people were already cool with 2.7+.

>> -
>>  import sys
>
> Why remove this blank line?

Oops -- I had put in a print_function import from __future__ for
testing. Must have lost the line when I took it back out. Is it worth
resubmitting to fix that?

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] test: Make gen-threads work with python3
  2014-10-31 18:04   ` Jesse Rosenthal
@ 2014-10-31 18:18     ` W. Trevor King
  0 siblings, 0 replies; 6+ messages in thread
From: W. Trevor King @ 2014-10-31 18:18 UTC (permalink / raw)
  To: Jesse Rosenthal; +Cc: notmuch

[-- Attachment #1: Type: text/plain, Size: 1076 bytes --]

On Fri, Oct 31, 2014 at 02:04:50PM -0400, Jesse Rosenthal wrote:
> W. Trevor King writes:
> > 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 ;).
> 
> The comprehension was already in the previous version, so I figured that
> people were already cool with 2.7+.

Ah, good point :).  Besides looking good to me, I can confirm that I
see a TypeError (and a lot of CPU usage ;) from T260-thread-order.sh
before this patch which is fixed by this patch.

Cheers,
Trevor

-- 
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

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] test: Make gen-threads work with python3
  2014-10-31 17:41 ` W. Trevor King
  2014-10-31 18:04   ` Jesse Rosenthal
@ 2014-11-01  8:08   ` Tomi Ollila
  1 sibling, 0 replies; 6+ messages in thread
From: Tomi Ollila @ 2014-11-01  8:08 UTC (permalink / raw)
  To: W. Trevor King, Jesse Rosenthal; +Cc: notmuch

On Fri, Oct 31 2014, "W. Trevor King" <wking@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@notmuchmail.org
> http://notmuchmail.org/mailman/listinfo/notmuch

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] test: Make gen-threads work with python3
  2014-10-31 17:33 [PATCH] test: Make gen-threads work with python3 Jesse Rosenthal
  2014-10-31 17:41 ` W. Trevor King
@ 2014-11-02 19:03 ` David Bremner
  1 sibling, 0 replies; 6+ messages in thread
From: David Bremner @ 2014-11-02 19:03 UTC (permalink / raw)
  To: Jesse Rosenthal, notmuch

Jesse Rosenthal <jrosenthal@jhu.edu> writes:

> python3 doesn't allow dictionaries to be initialized with non-string
> keywords. This presents problems on systems in which "python" means
> "python3". 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.

pushed.

d

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2014-11-02 19:03 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-10-31 17:33 [PATCH] test: Make gen-threads work with python3 Jesse Rosenthal
2014-10-31 17:41 ` W. Trevor King
2014-10-31 18:04   ` Jesse Rosenthal
2014-10-31 18:18     ` W. Trevor King
2014-11-01  8:08   ` Tomi Ollila
2014-11-02 19:03 ` 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).