Skip to content

behaviour difference when applying aspect to class vs instance #6

@chaoflow

Description

@chaoflow

What to do about this?

https://github.com/chaoflow/metachao/blob/master/src/metachao/tests/test_intermethod.py#L31

        class C(object):
            def f(self):
                return 1

            def g(self):
                return self.f() * 2

        class a1(Aspect):
            def f(self):
                return 10

        c = C()

        self.assertEqual(a1(C)().f(), 10)
        self.assertEqual(a1(c).f(), 10)
        # BUT:
        self.assertEqual(a1(C)().g(), 20)
        self.assertEqual(a1(c).g(), 2)

g in the last line is bound to c, not a1(c), and therefore c.f is called instead of a1.f.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions