[Patches] Patch to ihooks.py

Thomas Heller thomas.heller@ion-tof.com
Thu, 13 Apr 2000 16:34:11 +0200


ihooks.ModuleLoader does not implement reload(mod) correctly:
If mod has already been loaded by ModuleLoader, it has
been returned from a cache. Added an additional parameter
to import_it() to force reloading.


*** ihooks.old.py Thu Apr 13 16:26:06 2000
--- ihooks.py Thu Apr 13 16:27:18 2000
***************
*** 467,480 ****
                  if not submod:
                      raise ImportError, "No module named " + subname
  
!     def import_it(self, partname, fqname, parent):
          if not partname:
              raise ValueError, "Empty module name"
          try:
-             return self.modules[fqname]
-         except KeyError:
-             pass
-         try:
              path = parent and parent.__path__
          except AttributeError:
              return None
--- 467,481 ----
                  if not submod:
                      raise ImportError, "No module named " + subname
  
!     def import_it(self, partname, fqname, parent, force_load=0):
          if not partname:
              raise ValueError, "Empty module name"
+         if not force_load:
+             try:
+                 return self.modules[fqname]
+             except KeyError:
+                 pass
          try:
              path = parent and parent.__path__
          except AttributeError:
              return None
***************
*** 489,499 ****
      def reload(self, module):
          name = module.__name__
          if '.' not in name:
!             return self.import_it(name, name, None)
          i = string.rfind(name, '.')
          pname = name[:i]
          parent = self.modules[pname]
!         return self.import_it(name[i+1:], name, parent)
  
  
  default_importer = None
--- 490,500 ----
      def reload(self, module):
          name = module.__name__
          if '.' not in name:
!             return self.import_it(name, name, None, force_load=1)
          i = string.rfind(name, '.')
          pname = name[:i]
          parent = self.modules[pname]
!         return self.import_it(name[i+1:], name, parent, force_load=1)
  
  
  default_importer = None

Disclaimer:

I confirm that, to the best of my knowledge and belief, this
contribution is free of any claims of third parties under
copyright, patent or other rights or interests ("claims").  To
the extent that I have any such claims, I hereby grant to CNRI a
nonexclusive, irrevocable, royalty-free, worldwide license to
reproduce, distribute, perform and/or display publicly, prepare
derivative versions, and otherwise use this contribution as part
of the Python software and its related documentation, or any
derivative versions thereof, at no cost to CNRI or its licensed
users, and to authorize others to do so.

I acknowledge that CNRI may, at its sole discretion, decide
whether or not to incorporate this contribution in the Python
software and its related documentation.  I further grant CNRI
permission to use my name and other identifying information
provided to CNRI by me for use in connection with the Python
software and its related documentation.