Merge lp:~daniel-thewatkins/vmbuilder/mfdiff into lp:~ubuntu-on-ec2/vmbuilder/mfdiff

Proposed by Dan Watkins on 2017-08-15
Status: Merged
Merged at revision: 20
Proposed branch: lp:~daniel-thewatkins/vmbuilder/mfdiff
Merge into: lp:~ubuntu-on-ec2/vmbuilder/mfdiff
Diff against target: 23 lines (+12/-1)
1 file modified
mfdiff (+12/-1)
To merge this branch: bzr merge lp:~daniel-thewatkins/vmbuilder/mfdiff
Reviewer Review Type Date Requested Status
Philip Roche 2017-08-15 Approve on 2017-08-15
Chris Glass (community) 2017-08-15 Approve on 2017-08-15
Review via email: mp+329034@code.launchpad.net
To post a comment you must log in.
Chris Glass (tribaal) wrote :

Nice!

TIL: operator.methodcaller.

+1

review: Approve
Philip Roche (philroche) wrote :

+1

review: Approve
Philip Roche (philroche) wrote :

I did approve this but I'm now a little confused after reading the docstring for operator.methodcaller.

"""
Return a callable object that calls the given method on its operand.
After f = methodcaller('name'), the call f(r) returns r.name().
After g = methodcaller('name', 'date', foo=1), the call g(r) returns
r.name('date', foo=1).
"""

When calling viewkeys do we need to use six as viewkeys' operand?

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'mfdiff'
2--- mfdiff 2017-06-27 18:56:52 +0000
3+++ mfdiff 2017-08-15 13:28:06 +0000
4@@ -39,7 +39,18 @@
5 import apt
6 import requests
7 from debian.changelog import Changelog
8-from six import iteritems, viewkeys
9+from six import PY3, iteritems
10+
11+try:
12+ from six import viewkeys
13+except ImportError:
14+ # The version of six in trusty doesn't have viewkeys, so pull in the six
15+ # code from a more recent version if we can't get it directly from six.
16+ import operator
17+ if PY3:
18+ viewkeys = operator.methodcaller("keys")
19+ else:
20+ viewkeys = operator.methodcaller("viewkeys")
21
22 try:
23 from apt import VersionCompare as version_compare

Subscribers

People subscribed via source and target branches

to all changes: