diff options
author | Stanislav Laznicka <slaznick@redhat.com> | 2017-07-20 09:55:05 +0200 |
---|---|---|
committer | Pavel Vomacka <pvomacka@redhat.com> | 2017-07-27 10:28:58 +0200 |
commit | 5ff1de84909dd65c44b9aa48000b9e73a7a93716 (patch) | |
tree | 017c715966cbbd5e883912b8142f5551bf4aa825 /ipalib | |
parent | bf4dae70e0d163f4d485771d7d163169748fa6b3 (diff) | |
download | freeipa-5ff1de84909dd65c44b9aa48000b9e73a7a93716.tar.gz freeipa-5ff1de84909dd65c44b9aa48000b9e73a7a93716.tar.xz freeipa-5ff1de84909dd65c44b9aa48000b9e73a7a93716.zip |
parameters: relax type checks
Previously, the type check of the Param class did only allow
the parameters to only have a value that's of a direct type.
However, that's nonsensically restrictive. For example, if
there's an interface implemented as an `ABCMeta` class then
the check for type fails since the interface's type is
`ABCMeta` instead of directly a `type`. Among others,
this is the case for cryptography.x509.Certificate.
Being a type is a transitive property of a Python object and we
should respect that in our framework.
https://pagure.io/freeipa/issue/4985
Reviewed-By: Fraser Tweedale <ftweedal@redhat.com>
Reviewed-By: Rob Crittenden <rcritten@redhat.com>
Reviewed-By: Martin Basti <mbasti@redhat.com>
Diffstat (limited to 'ipalib')
-rw-r--r-- | ipalib/parameters.py | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/ipalib/parameters.py b/ipalib/parameters.py index 107cc9010..7f19642e2 100644 --- a/ipalib/parameters.py +++ b/ipalib/parameters.py @@ -467,17 +467,14 @@ class Param(ReadOnly): value = kind(value) elif type(value) is str: value = kind([value]) - if ( - type(kind) is type and not isinstance(value, kind) - or - type(kind) is tuple and not isinstance(value, kind) - ): + if kind is callable and not callable(value): raise TypeError( - TYPE_ERROR % (key, kind, value, type(value)) + CALLABLE_ERROR % (key, value, type(value)) ) - elif kind is callable and not callable(value): + elif (isinstance(kind, (type, tuple)) and + not isinstance(value, kind)): raise TypeError( - CALLABLE_ERROR % (key, value, type(value)) + TYPE_ERROR % (key, kind, value, type(value)) ) kw[key] = value elif key not in ('required', 'multivalue'): @@ -502,7 +499,7 @@ class Param(ReadOnly): self.nice = '%s(%r)' % (self.__class__.__name__, self.param_spec) # Make sure no unknown kw were given: - assert all(type(t) is type for t in self.allowed_types) + assert all(isinstance(t, type) for t in self.allowed_types) if not set(t[0] for t in self.kwargs).issuperset(self.__kw): extra = set(kw) - set(t[0] for t in self.kwargs) raise TypeError( |