Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always getattr() in lazy import machinery #1963

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions openff/toolkit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading