On 01/28/2016 05:06 PM, Tomas Babej wrote:
On 01/28/2016 04:44 PM, Martin Babinsky wrote:
On 01/28/2016 03:20 PM, Tomas Babej wrote:
On 01/27/2016 03:58 PM, Martin Babinsky wrote:
On 01/18/2016 06:43 PM, Martin Babinsky wrote:
A little patch that should make some future pylint errors disappear.
Attaching updated patch that does not promote direct molestation of
instance dictionaries.
Patch looks good, one thing I am concerened about though is that
__todict__ now returns a direct reference to the internal, mutable dict,
and no longer a (shallow) copy.
Maybe we should use dict.copy() there?
Tomas
Ah I didn't realize that. Fixed in updated patch.
Nitpick: Sorry for being misleading - I did not mean to suggest invoking
the method using the dict type directly. While being equivalent, the
dict.copy(self.__options)
it's less idiomatic than:
self.__options.copy()
Tomas
Ah sorry I forgot how to python again.
Attaching patch.
--
Martin^3 Babinsky
From ab10808ca8124499f021f45dfef91fa64cbe495b Mon Sep 17 00:00:00 2001
From: Martin Babinsky <[email protected]>
Date: Mon, 18 Jan 2016 18:35:52 +0100
Subject: [PATCH] ipalib/cli.py: pythonify Collector class
The implementation of Collector class is hard for pylint to chew and unwieldy.
This patch rewrites the class to a more readable and pythonic form.
---
ipalib/cli.py | 22 ++++++++++++++++------
1 file changed, 16 insertions(+), 6 deletions(-)
diff --git a/ipalib/cli.py b/ipalib/cli.py
index 136e0aeb8b876b2fe021f08e49a85a0fdeb4b21b..55204169d7caa06615d7d4144bfe845acec75368 100644
--- a/ipalib/cli.py
+++ b/ipalib/cli.py
@@ -972,20 +972,30 @@ cli_application_commands = (
class Collector(object):
def __init__(self):
- object.__setattr__(self, '_Collector__options', {})
+ self.__dict__.update(options={})
+ self.options = {} # silence pylint
def __setattr__(self, name, value):
- if name in self.__options:
- v = self.__options[name]
+ if name in dir(self):
+ object.__setattr__(self, name, value)
+ else:
+ self.__setitem__(name, value)
+
+ def __getitem__(self, item):
+ return self.options[item]
+
+ def __setitem__(self, key, value):
+ if key in self.options:
+ v = self.options[key]
if type(v) is tuple:
value = v + (value,)
else:
value = (v, value)
- self.__options[name] = value
- object.__setattr__(self, name, value)
+ self.options[key] = value
def __todict__(self):
- return dict(self.__options)
+ return self.options.copy()
+
class CLIOptionParserFormatter(optparse.IndentedHelpFormatter):
def format_argument(self, name, help_string):
--
2.5.0
--
Manage your subscription for the Freeipa-devel mailing list:
https://www.redhat.com/mailman/listinfo/freeipa-devel
Contribute to FreeIPA: http://www.freeipa.org/page/Contribute/Code