← Back to team overview

beeseek-devs team mailing list archive

[Branch ~beeseek-devs/beeseek/trunk] Rev 199: Do not raise a warning when an attribute is declared in __slots__.

 

------------------------------------------------------------
revno: 199
committer: Andrea Corbellini <andrea.corbellini@xxxxxxxxxxx>
branch nick: interfaces
timestamp: Sat 2009-01-17 17:30:48 +0100
message:
  Do not raise a warning when an attribute is declared in __slots__.
modified:
  beeseek/interfaces.py

=== modified file 'beeseek/interfaces.py'
--- a/beeseek/interfaces.py	2009-01-14 16:32:12 +0000
+++ b/beeseek/interfaces.py	2009-01-17 16:30:48 +0000
@@ -23,7 +23,7 @@
 
 import sys
 import warnings
-from types import MethodType, NoneType
+from types import MethodType, NoneType, MemberDescriptorType
 from beeseek.utils import get_argcount
 
 __all__ = ['Interface', 'implements', 'ImplementationWarning']
@@ -106,22 +106,28 @@
                 if name not in attrs:
                     # Base classes can skip the declaration of some attributes
                     if not isbaseclass:
-                        warnings.warn('%s is required by %r, but is not '
-                            'declared' % (name, interface),
+                        warnings.warn('%s is required by %s, but is not '
+                            'declared' % (name, interface.__name__),
                             ImplementationWarning, 2)
                     continue
 
                 value = getattr(interface, name)
-                if isinstance(value, MethodType):
+                attr = attrs[name]
+
+                if isinstance(attr, MemberDescriptorType):
+                    # If the attribute has been declared in __slots__, we
+                    # can't continue with the checks
+                    continue
+                elif isinstance(value, MethodType):
                     # The attribute should be a function
-                    if not isinstance(attrs[name], MethodType):
+                    if not isinstance(attr, MethodType):
                         warnings.warn('%s should be a method' % name,
                             ImplementationWarning, 2)
                         continue
 
                     # Check the number of arguments
                     needargs = get_argcount(value)
-                    usedargs = get_argcount(attrs[name])
+                    usedargs = get_argcount(attr)
                     if (needargs[1] and (needargs != usedargs)
                        or (needargs[0] > usedargs[0]
                        or needargs[2] != needargs[2])):
@@ -141,10 +147,10 @@
                     # Base classes can use None for attributes which don't
                     # have a default value
                     if isbaseclass:
-                        value = value + (NoneType,)
+                        value += (NoneType,)
 
                     # Check if the variable type is correct
-                    if not any(isinstance(attrs[name], cls or NoneType)
+                    if not any(isinstance(attr, cls or NoneType)
                                for cls in value):
                         warnings.warn('%s should be of type %r' %
                             (name, value), ImplementationWarning, 2)



--
BeeSeek mainline
https://code.launchpad.net/~beeseek-devs/beeseek/trunk

You are receiving this branch notification because you are subscribed to it.