-
Notifications
You must be signed in to change notification settings - Fork 16
Switch to lazy module imports #73
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please give me until tomorrow to look at this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an abomination lol. While I definitely appreciate the motivation, I worry that this is introducing a maintenance nightmare down the line
from .policy import PolicyRouter | ||
|
||
return PolicyRouter | ||
raise AttributeError("fmodule {__name__} has no attribute {name}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
raise AttributeError("fmodule {__name__} has no attribute {name}") | |
raise AttributeError(f"module {__name__} has no attribute {name}") |
How is this harder to maintain than what we had before? It's just more verbose, not more complex. I can implement the getattr method to grab the imports from a dictionary so future updates are only one line, but you said it looked too complex. |
Oh if we're choosing between the two options I would prefer the other one. With this approach every new API added needs a corresponding else block in an
|
See #83 |
Use lazy imports for modules so that you only import the the classes you actually use. For each submodule like actors, controller, data, etc you define the public apis at the top and then define a getattr method to import them only when requested. This will make imports faster and avoid, avoid circular dependencies, and make optional dependencies easier to manage. At the app level, users would be expected to import
from forge.actor import Policy
orfrom forge.data import collate_packed
.