clear repo imports before returning from sys.module

This commit is contained in:
sneakers-the-rat 2023-10-04 22:32:53 -07:00
parent 0f4f2dd683
commit 15d1f0d7b1

View file

@ -730,6 +730,10 @@ class PydanticProvider(Provider):
module_name = self.module_name(namespace, version) module_name = self.module_name(namespace, version)
namespace_name = module_name + '.namespace' namespace_name = module_name + '.namespace'
if not allow_repo:
self._clear_package_imports()
if namespace_name in sys.modules: if namespace_name in sys.modules:
return sys.modules[namespace_name] return sys.modules[namespace_name]
@ -741,8 +745,7 @@ class PydanticProvider(Provider):
if path is None or not path.exists(): if path is None or not path.exists():
_ = self.build(namespace, version=version) _ = self.build(namespace, version=version)
if not allow_repo:
self._clear_package_imports()
module = self.import_module(namespace, version) module = self.import_module(namespace, version)
return module return module