diff options
author | Petr Viktorin <pviktori@redhat.com> | 2015-08-11 13:51:14 +0200 |
---|---|---|
committer | Jan Cholasta <jcholast@redhat.com> | 2015-09-01 11:42:01 +0200 |
commit | 3bf91eab25c602a6fad2665456f57e8629c5a6f4 (patch) | |
tree | 52f713e898a385d57a914d539a7da9a20fc20166 /ipapython/install | |
parent | dd16cc98b0d67f1448bf9de25f8adce512b1431c (diff) | |
download | freeipa-3bf91eab25c602a6fad2665456f57e8629c5a6f4.tar.gz freeipa-3bf91eab25c602a6fad2665456f57e8629c5a6f4.tar.xz freeipa-3bf91eab25c602a6fad2665456f57e8629c5a6f4.zip |
Use Python3-compatible dict method names
Python 2 has keys()/values()/items(), which return lists,
iterkeys()/itervalues()/iteritems(), which return iterators,
and viewkeys()/viewvalues()/viewitems() which return views.
Python 3 has only keys()/values()/items(), which return views.
To get iterators, one can use iter() or a for loop/comprehension;
for lists there's the list() constructor.
When iterating through the entire dict, without modifying the dict,
the difference between Python 2's items() and iteritems() is
negligible, especially on small dicts (the main overhead is
extra memory, not CPU time). In the interest of simpler code,
this patch changes many instances of iteritems() to items(),
iterkeys() to keys() etc.
In other cases, helpers like six.itervalues are used.
Reviewed-By: Christian Heimes <cheimes@redhat.com>
Reviewed-By: Jan Cholasta <jcholast@redhat.com>
Diffstat (limited to 'ipapython/install')
-rw-r--r-- | ipapython/install/cli.py | 2 | ||||
-rw-r--r-- | ipapython/install/core.py | 2 | ||||
-rw-r--r-- | ipapython/install/util.py | 4 |
3 files changed, 5 insertions, 3 deletions
diff --git a/ipapython/install/cli.py b/ipapython/install/cli.py index 1ba9a815c..54ca58d26 100644 --- a/ipapython/install/cli.py +++ b/ipapython/install/cli.py @@ -145,7 +145,7 @@ class ConfigureTool(admintool.AdminTool): help="unattended (un)installation never prompts the user", ) - for group, opt_group in groups.iteritems(): + for group, opt_group in groups.items(): parser.add_option_group(opt_group) super(ConfigureTool, cls).add_options(parser, diff --git a/ipapython/install/core.py b/ipapython/install/core.py index c313c278e..dac8883fe 100644 --- a/ipapython/install/core.py +++ b/ipapython/install/core.py @@ -229,7 +229,7 @@ class Configurable(object): setattr(self, name, value) if kwargs: - extra = sorted(kwargs.keys()) + extra = sorted(kwargs) raise TypeError( "{0}() got {1} unexpected keyword arguments: {2}".format( type(self).__name__, diff --git a/ipapython/install/util.py b/ipapython/install/util.py index 58da7bb77..12530d45a 100644 --- a/ipapython/install/util.py +++ b/ipapython/install/util.py @@ -8,6 +8,8 @@ Utilities. import sys +import six + def raise_exc_info(exc_info): """ @@ -155,7 +157,7 @@ class InnerClassMeta(type): except KeyError: cls, name, value = None, None, None for cls in obj_type.__mro__: - for name, value in cls.__dict__.iteritems(): + for name, value in six.iteritems(cls.__dict__): if value is self: break if value is self: |