[Modeling-users] Models and import order
Status: Abandoned
Brought to you by:
sbigaret
From: Mario R. <ma...@ru...> - 2003-11-10 12:47:26
|
Hi all, I have been surprised with an ImportError ("cannot import name <CustomClass>") that occurs only for some custom object Classes. I have traced it down to the order that the imports are declared in the module that uses the model. In my particular case, I have the following pymodel (sketch): model.entities = [ Entity('A_1', ...), Entity('A_2', ...), Entity('A_2sub', parent='A_2' ...), Entity('B_1', ...), Entity('B_1sub', parent='B_1', ...), ] model.associations=[ Association('A_2','A_1', ... ), Association('B_1','B_1sub', ...), ] In the module that uses the model, if I import in the order: from pympack.B_1 import B_1 from pympack.B_1sub import B_1sub from pympack.A_1 import A_1 from pympack.A_2 import A_2 from pympack.A_2sub import A_2sub I get the ImportError: cannot import name B_1 However, all works fine if I change the import order to: from pympack.A_1 import A_1 from pympack.A_2 import A_2 from pympack.A_2sub import A_2sub from pympack.B_1 import B_1 from pympack.B_1sub import B_1sub I found this very confusing, especially given also that the "A" and "B" sets of classes exist in distinct inheritance hierarchies, and with no relations across the hierarchies. They just happen to be two distinct models, in the same model! Is there something I do not see here, or is this a bug? Is there a relation, or are there constraints to respect, between the import order and entity definition order in a model? (BTW, I am using last CVS version) mario |