-
-
Notifications
You must be signed in to change notification settings - Fork 315
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
feat: A way to warn user on default variable usage #454
base: develop
Are you sure you want to change the base?
Conversation
Your PR was set to target |
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.
I like this idea because it is a popular trap - not the obvious use of defaults. However, I would ask you to rethink your use of the logging. Also, could you please amend the tests and write a short note in the change log. Thank you!
@@ -391,6 +394,8 @@ def get_value(self, var, cast=None, default=NOTSET, parse_default=False): | |||
raise ImproperlyConfigured(error_msg) from exc | |||
|
|||
value = default | |||
if self._WARN_ON_DEFAULT_VALUE_USAGE: | |||
logger.warn(f"Variable '{var}' is using a default variable.") |
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.
Here is a tutorial-style HOWTO taking you through the steps in using the logging module. https://docs.python.org/3/howto/logging.html
warnings.warn()
in library code if the issue is avoidable and the client application should be modified to eliminate the warning
logging.warning()
if there is nothing the client application can do about the situation, but the event should still be noted
Considering the above, do you still think that the logging
is the better solution here?
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.
Thinking about it again, I have to agree with you. the pythonic warning package is a better substitute for this case.
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.
Could you please made the necessary changes?
This PR added a way to warn users of any variable that is using their default values.