summaryrefslogtreecommitdiffstats
path: root/ipalib/errors.py
diff options
context:
space:
mode:
authorJason Gerard DeRose <jderose@redhat.com>2008-09-02 16:42:39 +0000
committerJason Gerard DeRose <jderose@redhat.com>2008-09-02 16:42:39 +0000
commit6697b955eea6c5170cd68fef130d415ef3fa69cc (patch)
tree6302557084b1b01f834ca5b7719970b4807e7d8e /ipalib/errors.py
parent5af91df9a58c5066cbd526561886023d5edbfc0f (diff)
downloadfreeipa-6697b955eea6c5170cd68fef130d415ef3fa69cc.tar.gz
freeipa-6697b955eea6c5170cd68fef130d415ef3fa69cc.tar.xz
freeipa-6697b955eea6c5170cd68fef130d415ef3fa69cc.zip
227: check_type() and check_isinstance() now take arguments in (value, type_, name) order so the first two match the built-in isinstance() call signature
Diffstat (limited to 'ipalib/errors.py')
-rw-r--r--ipalib/errors.py26
1 files changed, 13 insertions, 13 deletions
diff --git a/ipalib/errors.py b/ipalib/errors.py
index 8c1df455..1b556c33 100644
--- a/ipalib/errors.py
+++ b/ipalib/errors.py
@@ -23,17 +23,17 @@ All custom errors raised by `ipalib` package.
TYPE_FORMAT = '%s: need a %r; got %r'
-def raise_TypeError(name, type_, value):
+def raise_TypeError(value, type_, name):
"""
Raises a TypeError with a nicely formatted message and helpful attributes.
The TypeError raised will have three custom attributes:
- ``name`` - The name (identifier) of the argument in question.
+ ``value`` - The value (of incorrect type) passed as argument.
``type`` - The type expected for the argument.
- ``value`` - The value (of incorrect type) passed as argument.
+ ``name`` - The name (identifier) of the argument in question.
There is no edict that all TypeError should be raised with raise_TypeError,
but when it fits, use it... it makes the unit tests faster to write and
@@ -48,40 +48,40 @@ def raise_TypeError(name, type_, value):
raise e
TypeError: message: need a <type 'str'>; got u'Hello.'
- :param name: The name (identifier) of the argument in question.
+ :param value: The value (of incorrect type) passed as argument.
:param type_: The type expected for the argument.
- :param value: The value (of incorrect type) passed argument.
+ :param name: The name (identifier) of the argument in question.
"""
- assert type(name) is str, TYPE_FORMAT % ('name', str, name)
assert type(type_) is type, TYPE_FORMAT % ('type_', type, type_)
assert type(value) is not type_, 'value: %r is a %r' % (value, type_)
+ assert type(name) is str, TYPE_FORMAT % ('name', str, name)
e = TypeError(TYPE_FORMAT % (name, type_, value))
- setattr(e, 'name', name)
- setattr(e, 'type', type_)
setattr(e, 'value', value)
+ setattr(e, 'type', type_)
+ setattr(e, 'name', name)
raise e
-def check_type(name, type_, value, allow_None=False):
+def check_type(value, type_, name, allow_None=False):
assert type(name) is str, TYPE_FORMAT % ('name', str, name)
assert type(type_) is type, TYPE_FORMAT % ('type_', type, type_)
assert type(allow_None) is bool, TYPE_FORMAT % ('allow_None', bool, allow_None)
if value is None and allow_None:
return
if type(value) is not type_:
- raise_TypeError(name, type_, value)
+ raise_TypeError(value, type_, name)
return value
-def check_isinstance(name, type_, value, allow_None=False):
- assert type(name) is str, TYPE_FORMAT % ('name', str, name)
+def check_isinstance(value, type_, name, allow_None=False):
assert type(type_) is type, TYPE_FORMAT % ('type_', type, type_)
+ assert type(name) is str, TYPE_FORMAT % ('name', str, name)
assert type(allow_None) is bool, TYPE_FORMAT % ('allow_None', bool, allow_None)
if value is None and allow_None:
return
if not isinstance(value, type_):
- raise_TypeError(name, type_, value)
+ raise_TypeError(value, type_, name)
return value