-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
app.config.from_object() missleading name -> app.config.from_module() would be better ? #1895
Comments
Or if follow documentation:
then we have bug. So mayby it shoud be fixed ? |
That method works on more than just modules. It would also work on classes or instances. It is more of a duck typing than anything else, as it looks for properties on an object. |
Start server and observe what is going on: And if You later check app.config You will not see there is TEST.
only works for module. For object we shoud have:
or
So again: |
I agree, the usage of dir there is a bizarre choice. Not what I would use for a class, an instance or a module. |
How to deal with it ? |
We have:
I am afraid we can not deal with all this cases with one simple method "from_object". So maybe it would be better to resign from "from_object()", and maybe create more fine tuned methods like "from_module()", "from_instance()", ... or maybe just one simple method "from_dict()" that would filter ony upper case keys
|
I think I like the more intuitive naming.
Then, I would leave
Thoughts? |
Although, from_module(), from_instance() are not different, I guest from_object() was introduced because we want to keep Sanic So to keep it that way maybe: Aproach 1)
Aproach 2)
And leave:
|
I'm not keen on changing the existing behavior. If we want a more proper method to load from any sort of input, then maybe it's Between now and the end of the year we are on a breaking change freeze. |
You are 100% right though. Unopinionated and flexible, but smart defaults and easy to use api to enable development. |
Can You please take a look at this (#1903) aproach ? I was able to replace:
with one smiple (6 lines of code):
and replace "loading module from file code" in
in a favour of
that uses python 3.5+ method to load module from file path |
We refactored it in #1903 |
Name of method
app.config.from_object()
is missleading somehow.
I thought I could:
but it does not work.
In such case I simply have to:
app.config.from_object(my_conf)
only works in such scenario:
So I suggest maybe the name of this method should be
app.config.from_module(...) ???
The text was updated successfully, but these errors were encountered: