Python 3 port of ‘lockfile’ (was: Py3k port of python-daemon)

Ben Finney ben+python at benfinney.id.au
Sun Jun 3 01:57:12 UTC 2012


Aaron Maxwell has put work into porting the ‘lockfile’ library to Python 3,
so I'm responding to that work here on the ‘python-lockfile-devel’ forum.

Anyone interested in this discussion on ‘lockfile’ development, visit
<URL:http://lists.alioth.debian.org/mailman/listinfo/python-lockfile-devel>
and subscribe.

Now for the response:


On 19-May-2012, Aaron Maxwell wrote:

> Based on my experiences porting Python-daemon 1.5.5 to work on our Python
> 3.2 stack, I have ported it to over to the (recent) tip of the mainline
> branch.
> Ben, you can get the merge bundles here (created via bzr send):
> 
> http://files.redsymbol.net/bfinney/lockfile-amax-py3k.gz

This changeset is relatively small, and is done well.

Here are the parts I need to specifically respond to:

> === modified file 'test/scaffold.py'
> --- test/scaffold.py	2010-12-07 10:54:10 +0000
> +++ test/scaffold.py	2012-05-22 22:51:15 +0000
> @@ -306,7 +307,7 @@
>  
>      def setUp(self):
>          """ Set up test fixtures. """
> -        for exc_type, params in self.valid_exceptions.items():
> +        for exc_type, params in list(self.valid_exceptions.items()):

One of the good improvements in Python 3 is that built-ins like
‘dict.items’ now tend to return iterators, not lists.

If you actually *need* the list, then wrapping the call in the ‘list’
creator is needed. For just iterating over the result, though, it's
pointless to create a list object which will be discarded afterward.

I suspect the above was the result of the ‘2to3’ tool, which must assume in
the absence of an explicit Python 2 request for an iterator that the list
was actually wanted. In this case, it's not.

With that in mind, can I ask you to revert the above (to allow the ‘for’
statement to iterate directly over the iterator object, without creating a
redundant list object)?

> @@ -316,13 +317,13 @@
>  
>      def test_exception_instance(self):
>          """ Exception instance should be created. """
> -        for params in self.valid_exceptions.values():
> +        for params in list(self.valid_exceptions.values()):
>              instance = params['instance']
>              self.failIfIs(None, instance)
>  
>      def test_exception_types(self):
>          """ Exception instances should match expected types. """
> -        for params in self.valid_exceptions.values():
> +        for params in list(self.valid_exceptions.values()):
>              instance = params['instance']
>              for match_type in params['types']:
>                  match_type_name = match_type.__name__

And the same for the above two iterators.


Thank you for working on this.

-- 
 \        “Members of the general public commonly find copyright rules |
  `\        implausible, and simply disbelieve them.” —Jessica Litman, |
_o__)                                              _Digital Copyright_ |
Ben Finney <ben at benfinney.id.au>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.alioth.debian.org/pipermail/python-daemon-devel/attachments/20120603/780369d3/attachment.pgp>


More information about the python-daemon-devel mailing list