Type implications bug

"Alberto Valverde" <[email protected]>
Newsgroups gmane.comp.python.peak
Message-ID <[email protected]>
Hi,

I've attached a unit test which blows up peak/rules/indexing.py._get_mro.

Regards,
Alberto

_______________________________________________
PEAK mailing list
[email protected]
http://www.eby-sarna.com/mailman/listinfo/peak
test_subclass.py (text/x-python, 974 B)
from inspect import isclass
import unittest
from peak.rules import when, abstract

class A(object): pass
class B(A): pass

@abstract
def whats_this(obj):
    pass

@when(whats_this, "isclass(obj) and issubclass(obj, A)")
def say_it(obj):
    return "It's an A!"

@when(whats_this, "isclass(obj) and issubclass(obj, B)")
def say_it(obj):
    return "It's a B!"

@when(whats_this, (B,))
def say_it(obj):
    return "It's an B instance!"

@when(whats_this, (A,))
def say_it(obj):
    return "It's an A instance!"

class TestTypeImplications(unittest.TestCase):
    def test_issubclass_B_implies_issubclass_A(self):
        self.failUnlessEqual(whats_this(B), "It's a B!")
        self.failUnlessEqual(whats_this(A), "It's an A!")
        
    def test_isinstance_B_implies_isinstance_A(self):
        self.failUnlessEqual(whats_this(B()), "It's a B instance!")
        self.failUnlessEqual(whats_this(A()), "It's an A instance!")

if __name__ == "__main__":
    unittest.main()
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.