beeseek-devs team mailing list archive
-
beeseek-devs team
-
Mailing list archive
-
Message #00109
[Branch ~beeseek-devs/beeseek/trunk] Rev 195: Display a warning instead of raising an exception when an interface is
------------------------------------------------------------
revno: 195
committer: Andrea Corbellini <andrea.corbellini@xxxxxxxxxxx>
branch nick: interfaces
timestamp: Wed 2009-01-14 15:09:24 +0100
message:
Display a warning instead of raising an exception when an interface is
not well-implemented.
This may help developers in their work avoiding inconvenient bugs and
temporary changes to their classes.
modified:
beeseek/interfaces.py
=== modified file 'beeseek/interfaces.py'
--- a/beeseek/interfaces.py 2009-01-13 13:08:37 +0000
+++ b/beeseek/interfaces.py 2009-01-14 14:09:24 +0000
@@ -22,10 +22,11 @@
"""
import sys
+import warnings
from types import MethodType, NoneType
from beeseek.utils import get_argcount
-__all__ = ['Interface', 'implements', 'ImplementationError']
+__all__ = ['Interface', 'implements', 'ImplementationWarning']
if 'any' not in __builtins__:
@@ -52,8 +53,8 @@
raise TypeError('Cannot directly instance Interface')
-class ImplementationError(StandardError):
- """An error raised when an interface is not implemented correctly."""
+class ImplementationWarning(Warning):
+ """A warning shown when an interface is not implemented correctly."""
pass
@@ -104,10 +105,11 @@
# Check if the variable is declared
if name not in attrs:
# Base classes can skip the declaration of some attributes
- if isbaseclass:
- continue
- raise ImplementationError('%s is required by %r, but '
- 'is not declared' % (name, interface))
+ if not isbaseclass:
+ warnings.warn('%s is required by %r, but is not '
+ 'declared' % (name, interface),
+ ImplementationWarning)
+ continue
value = getattr(interface, name)
if isinstance(value, MethodType):
@@ -118,8 +120,9 @@
if (needargs[1] and (needargs != usedargs)
or (needargs[0] > usedargs[0]
or needargs[2] != needargs[2])):
- raise ImplementationError('Wrong number of arguments '
- 'for %s' % name)
+ warnings.warn('Wrong number of arguments for %s' %
+ name, ImplementationWarning)
+ continue
else:
# The attribute is a variable
# Its declaration in the interface may be a type or a
@@ -138,8 +141,9 @@
# Check if the variable type is correct
if not any(isinstance(attrs[name], cls or NoneType)
for cls in value):
- raise ImplementationError('%s should be of type %r' %
- (name, value))
+ warnings.warn('%s should be of type %r' %
+ (name, value), ImplementationWarning)
+ continue
# Return the class
return cls
@@ -151,7 +155,7 @@
should be subclasses of Interface.
It does several checks to ensure that the interface has been implemented
- correctly. In case of a bad implementation, ImplementationError is raised
+ correctly. In case of a bad implementation, ImplementationWarning is shown
when the class is created. The checks done are:
* all the attributes declared in the Interface must be present
--
BeeSeek mainline
https://code.launchpad.net/~beeseek-devs/beeseek/trunk
You are receiving this branch notification because you are subscribed to it.