diff runtime/doc/if_pyth.txt @ 4855:52850ef928f8 v7.3.1174

updated for version 7.3.1174 Problem: Python 2 and 3 use different ways to load modules. Solution: Use the same method. (ZyX)
author Bram Moolenaar <bram@vim.org>
date Wed, 12 Jun 2013 14:41:04 +0200
parents 96e154e825a7
children c458ff35497e
line wrap: on
line diff
--- a/runtime/doc/if_pyth.txt
+++ b/runtime/doc/if_pyth.txt
@@ -315,7 +315,7 @@ vim.path_hooks in sys.path_hooks python 
 {rtp}/python2 (or python3) and {rtp}/pythonx (for both python versions) for 
 each {rtp} found in 'runtimepath'.
 
-Implementation for python 2 is similar to the following, but written in C: >
+Implementation is similar to the following, but written in C: >
 
     from imp import find_module, load_module
     import vim
@@ -344,16 +344,16 @@ Implementation for python 2 is similar t
     # matter for python which object has find_module function attached to as 
     # an attribute.
     class VimPathFinder(object):
+        @classmethod
         def find_module(cls, fullname, path=None):
             try:
                 return VimModuleLoader(_find_module(fullname, fullname, path or vim._get_paths()))
             except ImportError:
                 return None
-        find_module = classmethod(find_module)
 
+        @classmethod
         def load_module(cls, fullname, path=None):
             return _find_module(fullname, fullname, path or vim._get_paths())
-        load_module = classmethod(load_module)
 
     def hook(path):
         if path == vim.VIM_SPECIAL_PATH:
@@ -363,30 +363,6 @@ Implementation for python 2 is similar t
 
     sys.path_hooks.append(hook)
 
-Implementation for python 3 is cleaner: code is similar to the following, but, 
-again, written in C: >
-
-    from importlib.machinery import PathFinder
-    import sys
-
-    class Finder(PathFinder):
-        @classmethod
-        def find_module(cls, fullname):
-            # see vim._get_paths below
-            new_path = _get_paths()
-
-            # super().find_module is also a class method
-            # super() is not used because this variant is easier to implement 
-            # in C
-            return PathFinder.find_module(fullname, new_path)
-
-    def path_hook(path):
-        if path == VIM_SPECIAL_PATH:
-            return Finder
-        raise ImportError
-
-    sys.path_hooks.append(path_hook)
-
 vim.VIM_SPECIAL_PATH					*python-VIM_SPECIAL_PATH*
 	String constant used in conjunction with vim path hook. If path hook 
 	installed by vim is requested to handle anything but path equal to 
@@ -402,8 +378,7 @@ vim.path_hook(path)					*python-path_hoo
 	You should not be using any of these directly except for vim.path_hook 
 	in case you need to do something with sys.meta_path. It is not 
 	guaranteed that any of the objects will exist in the future vim 
-	versions. In fact, find_module methods do not exists 
-	in python3.
+	versions.
 
 vim._get_paths						*python-_get_paths*
 	Methods returning a list of paths which will be searched for by path