Registering "Magic" Metaclass attributes

I have a meta baseclass that is similar to Django's model class. It creates class attributes in instances based on how the class is defined. It's called model.Struct below.

I want to "Teach" PyCharm how to interpret this definition so that it can offer code completion hints about the model attributes. I expect that I might need to write some code somewhere for PyCharm to run to interpret my metaclass.

As an example of what this model object does, here's a very simple test:

A Python UnitTest Member demonstrating model.Struct
    def test_constructor_args(self):
        """You can build structure instances using keyword arguments"""

        class SimpleABC(model.Struct):
            a = model.Field()
            b = model.Field()
            c = model.Field()

        inst = SimpleABC(b=2, c=3)
        self.assertEqual(0, inst.a)
        self.assertEqual(2, inst.b)
        self.assertEqual(3, inst.c)

        inst = SimpleABC(b=2, c=3, a= 1)
        self.assertEqual(1, inst.a)
        self.assertEqual(2, inst.b)
        self.assertEqual(3, inst.c)

prettyPrint();

I'd like the ability to type "inst." and have auto-complete suggest a, b and c as members. Is there a way to do this?

Please sign in to leave a comment.