mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
parameters: relax type checks
The type checks in ipalib.parameters were too strict. An object that inherits from a type should implement its public interface. This should allow us checking for types of objects whose class implementations are private to a module but they implement a certain public interface (which is typical for e.g. python-cryptography). https://pagure.io/freeipa/issue/7131
This commit is contained in:
parent
c9d710a446
commit
26d721e6ea
@ -848,8 +848,10 @@ class Param(ReadOnly):
|
||||
"""
|
||||
Convert a single scalar value.
|
||||
"""
|
||||
if type(value) in self.allowed_types:
|
||||
return value
|
||||
for t in self.allowed_types:
|
||||
if isinstance(value, t):
|
||||
return value
|
||||
|
||||
raise ConversionError(name=self.name, error=ugettext(self.type_error))
|
||||
|
||||
def validate(self, value, supplied=None):
|
||||
@ -879,7 +881,10 @@ class Param(ReadOnly):
|
||||
self._validate_scalar(value)
|
||||
|
||||
def _validate_scalar(self, value, index=None):
|
||||
if type(value) not in self.allowed_types:
|
||||
for t in self.allowed_types:
|
||||
if isinstance(value, t):
|
||||
break
|
||||
else:
|
||||
raise TypeError(
|
||||
TYPE_ERROR % (self.name, self.type, value, type(value))
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user