Re: [Modeling-users] Models and import order
Status: Abandoned
Brought to you by:
sbigaret
From: Sebastien B. <sbi...@us...> - 2003-11-10 13:35:14
|
Hi Mario, Okay, got it: this happens whenever you import a class with sub-classes at first. Current solution is: first import a class without sub-classes :/ Can you confirm that you used the '-B'/--base generation scheme? The -C/compact scheme does not suffer from this as far as I can see. Sorry, this is definitely a bug, and this is confusing indeed. I'm gonna review the python generation process and post here when this is corrected. If you find some time, could you fill in a bug report? -- S=E9bastien. Mario Ruggier <ma...@ru...> wrote: > Hi all, >=20 > I have been surprised with an ImportError ("cannot import name <CustomCla= ss>") > that occurs only for some custom object Classes. >=20 > 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): >=20 > model.entities =3D [ > Entity('A_1', ...), > Entity('A_2', ...), > Entity('A_2sub', parent=3D'A_2' ...), > Entity('B_1', ...), > Entity('B_1sub', parent=3D'B_1', ...), > ] >=20 > model.associations=3D[ > Association('A_2','A_1', ... ), > Association('B_1','B_1sub', ...), > ] >=20 > In the module that uses the model, if I import in the order: >=20 > 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 >=20 > I get the ImportError: cannot import name B_1 > However, all works fine if I change the import order to: >=20 > 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 >=20 > 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! >=20 > 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) >=20 > mario |