diff options
| author | Jan-Jaap Driessen <jdriessen@minddistrict.com> | 2020-10-01 13:02:38 +0200 |
|---|---|---|
| committer | Jan-Jaap Driessen <jdriessen@minddistrict.com> | 2020-10-01 13:02:38 +0200 |
| commit | 3fc878eb00deb9e2988ef651c74e09e39dd9d49a (patch) | |
| tree | 901fe55eed83a6ae56abd383bf267010f38351ac /src | |
| parent | 856ee6086af24792a0ff1f63bc6eb750de0892a3 (diff) | |
| download | zope-interface-3fc878eb00deb9e2988ef651c74e09e39dd9d49a.tar.gz | |
Use queryDirectTaggedValue to find invariants removes the need to keep track of invariants we have already seen.
Diffstat (limited to 'src')
| -rw-r--r-- | src/zope/interface/interface.py | 34 |
1 files changed, 13 insertions, 21 deletions
diff --git a/src/zope/interface/interface.py b/src/zope/interface/interface.py index 918383b..d100aae 100644 --- a/src/zope/interface/interface.py +++ b/src/zope/interface/interface.py @@ -875,29 +875,21 @@ class InterfaceClass(_InterfaceClassBase): def queryDescriptionFor(self, name, default=None): return self.get(name, default) - def __validateInvariants(self, obj, errors, seen): - for call in self.queryTaggedValue('invariants', []): - if call in seen: - continue - seen.add(call) - try: - call(obj) - except Invalid as e: - if errors is None: - raise - errors.append(e) - for base in self.__bases__: - try: - base.__validateInvariants(obj, errors, seen) - except Invalid: - if errors is None: - raise - if errors: - raise Invalid(errors) - def validateInvariants(self, obj, errors=None): """validate object to defined invariants.""" - self.__validateInvariants(obj, errors, set()) + + for iface in self.__iro__: + for invariant in iface.queryDirectTaggedValue('invariants', ()): + try: + invariant(obj) + except Invalid as error: + if errors is not None: + errors.append(error) + else: + raise + + if errors: + raise Invalid(errors) def queryTaggedValue(self, tag, default=None): """ |
