More Python module loading simplification
Slightly faster checking to see if a module is in a package. Issue #848
This commit is contained in:
parent
2a00d0f784
commit
355395200f
2 changed files with 4 additions and 4 deletions
|
|
@ -6282,7 +6282,7 @@ The code is generated into the pure Python module, foo.py, and merely imports th
|
|||
|
||||
<div class="targetlang">
|
||||
<pre>
|
||||
if __package__ or __name__.rpartition('.')[0]:
|
||||
if __package__ or '.' in __name__:
|
||||
from . import _foo
|
||||
else:
|
||||
import _foo
|
||||
|
|
@ -6367,7 +6367,7 @@ The default import loading code is thus different:
|
|||
|
||||
<div class="targetlang">
|
||||
<pre>
|
||||
if __package__ or __name__.rpartition('.')[0]:
|
||||
if __package__ or '.' in __name__:
|
||||
from ._foo import *
|
||||
else:
|
||||
from _foo import *
|
||||
|
|
|
|||
|
|
@ -693,13 +693,13 @@ public:
|
|||
* same package, otherwise load it as a global module.
|
||||
*/
|
||||
Printv(default_import_code, "# Import the low-level C/C++ module\n", NULL);
|
||||
Printv(default_import_code, "if __package__ or __name__.rpartition('.')[0]:\n", NULL);
|
||||
Printv(default_import_code, "if __package__ or '.' in __name__:\n", NULL);
|
||||
Printv(default_import_code, tab4, "from . import ", module, "\n", NULL);
|
||||
Printv(default_import_code, "else:\n", NULL);
|
||||
Printv(default_import_code, tab4, "import ", module, "\n", NULL);
|
||||
} else {
|
||||
Printv(default_import_code, "# Pull in all the attributes from the low-level C/C++ module\n", NULL);
|
||||
Printv(default_import_code, "if __package__ or __name__.rpartition('.')[0]:\n", NULL);
|
||||
Printv(default_import_code, "if __package__ or '.' in __name__:\n", NULL);
|
||||
Printv(default_import_code, tab4, "from .", module, " import *\n", NULL);
|
||||
Printv(default_import_code, "else:\n", NULL);
|
||||
Printv(default_import_code, tab4, "from ", module, " import *\n", NULL);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue