-
Notifications
You must be signed in to change notification settings - Fork 262
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
Issue 249 postponed configuration #251
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.
This is a big change that touches some of the most critical code and complicates the object lifecycle considerably. I am not even sure we want the deferred configuration in the first place.
Yeah, PR and issue are open for discussion to determine whether this PR will be useful. I just think that sometimes its not convenient nor beautiful to parse config at import time. I prefer factory pattern so made this PR. |
IMHO there's problem with our API design, but band-aiding it will not help, only make the problem harder to deal with later.
|
Can I do something to improve this PR? Or should I close it then? |
Maybe create some proxy/wrapper around class DatabaseWrapper:
def __init__(self):
self.db = None
def configure(self, **all_rapams):
self.db = Database(**all_rapams)
def check_configured(self):
if not self.db:
raise ValueError
def connect(self):
# proxies all methods to inner object
self.check_configured()
return self.db.connect()
class Database:
# this class would not be changed
pass
db = DatabaseWrapper()
def main():
params = parse_env_params()
db.configure(**params)
connect = db.connect() |
Closes #249