diff --git a/openff/toolkit/__init__.py b/openff/toolkit/__init__.py index 5fcd9bc70..a5fe42fa3 100644 --- a/openff/toolkit/__init__.py +++ b/openff/toolkit/__init__.py @@ -79,10 +79,13 @@ def __getattr__(name): obj_mod = _lazy_imports_obj.get(name) if obj_mod is not None: mod = importlib.import_module(obj_mod) - try: - return mod.__dict__[name] - except KeyError: # account for lazy loaders - return getattr(mod, name) + # This only causes an infinite recursive loop if an object that does not + # exist is declared in `_lazy_imports_obj` to be lazy loaded from the + # current module. Since there is no reason to include either an object + # from the current module or an object that does not exist in + # `_lazy_imports_obj`, and since the function would fail in this case + # anyway, this is safe. + return getattr(mod, name) lazy_mod = _lazy_imports_mod.get(name) if lazy_mod is not None: