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.
--
Martin^3 Babinsky
From fdb04f6a15c6a8983706916c52bfee407cb1509c 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..02a09d14b717640284361e453507b38c1172529d 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 = {} # shut up 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
+
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