Skip to content

Commit

Permalink
Merge pull request #172 from fxthomas/161-fix-modulenotfounderror-stdole
Browse files Browse the repository at this point in the history
Fix importing newly-created modules on Python 3
  • Loading branch information
vasily-v-ryabov authored Sep 10, 2020
2 parents ae2f519 + 07cc8cb commit 31d05e5
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions comtypes/client/_generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import sys
import comtypes.client
import comtypes.tools.codegenerator
import importlib

import logging
logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -150,6 +151,9 @@ def GetModule(tlib):
ofi = open(os.path.join(comtypes.client.gen_dir, modulename + ".py"), "w")
ofi.write(code)
ofi.close()
# clear the import cache to make sure Python sees newly created modules
if hasattr(importlib, "invalidate_caches"):
importlib.invalidate_caches()
return _my_import("comtypes.gen." + modulename)

def _CreateWrapper(tlib, pathname=None):
Expand Down Expand Up @@ -188,6 +192,9 @@ def _CreateWrapper(tlib, pathname=None):
setattr(comtypes.gen, modname, mod)
else:
ofi.close()
# clear the import cache to make sure Python sees newly created modules
if hasattr(importlib, "invalidate_caches"):
importlib.invalidate_caches()
mod = _my_import(fullname)
return mod

Expand Down

0 comments on commit 31d05e5

Please sign in to comment.