Update -relative import documentation to reflect runtime check.

This commit is contained in:
Mike Romberg 2016-06-06 13:43:58 -06:00
commit ac7157dfc6

View file

@ -5680,8 +5680,9 @@ class M2(pkg2.mod3.M3): pass
<p>By default, SWIG would generate <tt>mod2.py</tt> proxy file with <p>By default, SWIG would generate <tt>mod2.py</tt> proxy file with
<tt>import</tt> directive as in point 1. This can be changed with the <tt>import</tt> directive as in point 1. This can be changed with the
<tt>-relativeimport</tt> command line option. The <tt>-relativeimport</tt> instructs <tt>-relativeimport</tt> command line option. The <tt>-relativeimport</tt> instructs
SWIG to organize imports as in point 2 (for Python 2.x) or as in point 4 (for SWIG to organize imports as in point 2 (for Python < 2.7.0) or as in point 4
Python 3, that is when the -py3 command line option is enabled). In short, if you have for Python 2.7.0 and newer. This is a check done at the time the module is
imported. In short, if you have
<tt>mod2.i</tt> and <tt>mod3.i</tt> as above, then without <tt>mod2.i</tt> and <tt>mod3.i</tt> as above, then without
<tt>-relativeimport</tt> SWIG will write</p> <tt>-relativeimport</tt> SWIG will write</p>
@ -5696,21 +5697,15 @@ write</p>
<div class="targetlang"> <div class="targetlang">
<pre> <pre>
import sys
if sys.version_info >= (2, 7, 0):
from . import pkg2
import pkg1.pkg2.mod3
else:
import pkg2.mod3 import pkg2.mod3
</pre> </pre>
</div> </div>
<p>if <tt>-py3</tt> is not used, or</p>
<div class="targetlang">
<pre>
from . import pkg2
import pkg1.pkg2.mod3
</pre>
</div>
<p>when <tt>-py3</tt> is used.</p>
<p>You should avoid using relative imports and use absolute ones whenever <p>You should avoid using relative imports and use absolute ones whenever
possible. There are some cases, however, when relative imports may be possible. There are some cases, however, when relative imports may be
necessary. The first example is, when some (legacy) Python code refers entities necessary. The first example is, when some (legacy) Python code refers entities