Improve QtValueError wording for ensure_not_null.
This commit is contained in:
parent
8d15bbdded
commit
120d2e12b0
@ -131,7 +131,7 @@ def ensure_valid(obj):
|
|||||||
def ensure_not_null(obj):
|
def ensure_not_null(obj):
|
||||||
"""Ensure a Qt object with an .isNull() method is not null."""
|
"""Ensure a Qt object with an .isNull() method is not null."""
|
||||||
if obj.isNull():
|
if obj.isNull():
|
||||||
raise QtValueError(obj)
|
raise QtValueError(obj, null=True)
|
||||||
|
|
||||||
|
|
||||||
def check_qdatastream(stream):
|
def check_qdatastream(stream):
|
||||||
@ -322,12 +322,15 @@ class QtValueError(ValueError):
|
|||||||
|
|
||||||
"""Exception which gets raised by ensure_valid."""
|
"""Exception which gets raised by ensure_valid."""
|
||||||
|
|
||||||
def __init__(self, obj):
|
def __init__(self, obj, null=False):
|
||||||
try:
|
try:
|
||||||
self.reason = obj.errorString()
|
self.reason = obj.errorString()
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
self.reason = None
|
self.reason = None
|
||||||
err = "{} is not valid".format(obj)
|
if null:
|
||||||
|
err = "{} is null".format(obj)
|
||||||
|
else:
|
||||||
|
err = "{} is not valid".format(obj)
|
||||||
if self.reason:
|
if self.reason:
|
||||||
err += ": {}".format(self.reason)
|
err += ": {}".format(self.reason)
|
||||||
super().__init__(err)
|
super().__init__(err)
|
||||||
|
Loading…
Reference in New Issue
Block a user