From 81adedd7dd3433d600a584337dcff2335dc12e9b Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 6 Jun 2016 22:20:07 +0100 Subject: [PATCH] Python: Do not import all of sys when using -relativeimport --- Doc/Manual/Python.html | 5 +++-- Source/Modules/python.cxx | 10 +++++----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/Doc/Manual/Python.html b/Doc/Manual/Python.html index e6c23bc8c..83baa1a47 100644 --- a/Doc/Manual/Python.html +++ b/Doc/Manual/Python.html @@ -5697,12 +5697,13 @@ write

-import sys
-if sys.version_info >= (2, 7, 0):
+from sys import version_info
+if version_info >= (2, 7, 0):
     from . import pkg2
     import pkg1.pkg2.mod3
 else:
     import pkg2.mod3
+del version_info
 
diff --git a/Source/Modules/python.cxx b/Source/Modules/python.cxx index be7af9171..a7e76cb0f 100644 --- a/Source/Modules/python.cxx +++ b/Source/Modules/python.cxx @@ -1251,14 +1251,14 @@ public: Printf(out, "import %s%s%s%s\n", apkg, *Char(apkg) ? "." : "", pfx, mod); Delete(apkg); } else { - Printf(out, "import sys\n"); - Printf(out, "if sys.version_info >= (2, 7, 0):\n"); + Printf(out, "from sys import version_info\n"); + Printf(out, "if version_info >= (2, 7, 0):\n"); if (py3_rlen1) - Printf(out, tab4 "from . import %.*s\n", py3_rlen1, rpkg); + Printf(out, tab4 "from . import %.*s\n", py3_rlen1, rpkg); Printf(out, tab4 "from .%s import %s%s\n", rpkg, pfx, mod); Printf(out, "else:\n"); - Printf(out, tab4 "import %s%s%s%s\n", rpkg, *Char(rpkg) ? "." : "", - pfx, mod); + Printf(out, tab4 "import %s%s%s%s\n", rpkg, *Char(rpkg) ? "." : "", pfx, mod); + Printf(out, "del version_info\n"); Delete(rpkg); } return out;