[Freeipa-devel] [PATCH 0020] Add IntEnum parameter to ipalib

Petr Viktorin pviktori at redhat.com
Mon Oct 7 11:22:58 UTC 2013


On 10/04/2013 07:33 PM, Nathaniel McCallum wrote:
> This patch is preparatory for the OTP CLI patch.


 > +    def _convert_scalar(self, value, index=None):
 > +        return Int._convert_scalar(self, value, index=index)

That won't work. In Python 2 unbound methods (such as 
Int._validate_scalar) must be passed the correct type as self; passing 
an IntEnum instance like this will raise a TypeError.

You'll need to either use multiple inheritance (if you feel the 
framework isn't complex enough), or make a convert_int function, and 
then in both Int and IntEnum just call it and handle ValueError.

For validate_scalar it would probably be best to extend 
Param._validate_scalar to allow the class to define extra allowed types, 
and get rid of the reimplementation in Int.

-- 
Petr³




More information about the Freeipa-devel mailing list