Avoid to use package named "code" with embedded python methods using [Language = python]
Hello,
as it took me some time to figure out what's wrong, I would like to share this experience, so that you do not fall into the same trap.
I've just noticed that if you name your package "code" (all lowercase), in a class using some embedded python using [Language = python], you'll face the <THROW> *%Exception.PythonException <PYTHON EXCEPTION> 246 <class 'ModuleNotFoundError'>: No module named 'code.basics'; 'code' is not a package
Class code.basics Extends%RegisteredObject
{
ClassMethod Welcome() As%Status [ Language = python ]
{
print('Welcome!')
return True
}
}IRISAPP>w##class(code.basics).Welcome()
W##CLASS(code.basics).Welcome()
^
<THROW> *%Exception.PythonException <PYTHON EXCEPTION> 246 <class 'ModuleNotFoundError'>: No module named 'code.basics'; 'code' is not a packageIt works well with "Code" :
Class Code.basics Extends%RegisteredObject
{
ClassMethod Welcome() As%Status [ Language = python ]
{
print('Welcome!')
return True
}
}IRISAPP>w##class(Code.basics).Welcome()
Welcome!
1Comments
This is because "code" is a standard python module
https://docs.python.org/3/library/code.html
to fix this issue, I think the Intersystems developpers should hide user-made code in a custom module so it doesn't conflict when trying to load it
Anything that's in python sys.modules (plenty of other examples) isn't likely to work very well because of the way the namespaces are merged.