transcrypt import in import
<p>Using Transcrypt for python to javascript compiling I have 2 modules that need each other. For example: </p>

<p>myTest.py:</p>

<pre><code>import myTest2
def test():
    myTest2.test()
someConstant = 1
</code></pre>

<p>and myTest2.py:</p>

<pre><code>import myTest
def test():
    console.log(myTest.someConstant)
</code></pre>

<p>After compiling to javascript, and calling <code>myTest.test()</code> I get an RangeError: Maximum call stack size exceeded.
How can I avoid this, but keep 2 modules which use each other?
Thanks in advance.</p>

<p>In Transcrypt imports are resolved at compile time rather than runtime, since the compiler must know which modules to include in the generated JavaScript. Moreover, import resolution happens in one pass. This fact that resolution happens in a single pass means that mutual (or in general cyclic) imports are not supported.</p>

<p>So if you have two modules that require something of each other, the way to go is to factor that something out and put in in a third module, imported by both.</p>

<p>The fact that resolution happens at compile time also means that there's no point in runtime conditional imports, using 'if'. For conditional imports use __pragma__ ('ifdef', ...) which does its work compile time.</p>

<p>Restrictions like this are explained at:</p>

<p><a href="http://sterlicht.alwaysdata.net/transcrypt.org/docs/html/special_facilities.html#transcrypt-s-module-mechanism" rel="nofollow">http://sterlicht.alwaysdata.net/transcrypt.org/docs/html/special_facilities.html#transcrypt-s-module-mechanism</a></p>

javascript python transcrypt