Comments (9)
Thanks for pointing it out. That's true that user-friendliness would be improved very much using such approach. However that would be the first time that ecological
would try to invent its own parsing rules and language that is different from Python that I understand was one of original assumptions (straightforward and simple). Is it worth changing this approach?
from ecological.
If making exceptions (like I described in my "ideal" case above) is not on the table, would it still be possible to catch the exception from ast.literal_eval
and display a better error?
from ecological.
If making exceptions (like I described in my "ideal" case above) is not on the table
Everything is on the table. That would just require significant change of the library's philosophy and I am just looking for additional reasoning behind that.
would it still be possible to catch the exception from ast.literal_eval and display a better error?
What would be the better error in this case?
Currently Ecological
differentiates only between if something needs to be Python-evaluated or not and presented exception is the best that we have at the moment.
from ecological.
@thilp Can you provide an example of what error message you would expect here?
from ecological.
I think the most useful message in my case would have been something like:
ValueError: Invalid configuration for 'TEST_HI': expected 'True' or 'False' but got 'true'
ValueError: Invalid configuration for 'TEST_HI': value 'true' is not a valid Python expression
as it would have pointed me directly to the source of the error and proposed a fix. I would also have enjoyed a shorter stacktrace because I'm not interested in implementation details.
If making exceptions (like I described in my "ideal" case above) is not on the table
Everything is on the table. That would just require significant change of the library's philosophy and I am just looking for additional reasoning behind that.
Imho libraries should strike a balance between happy users and sustainable growth. It is totally fine if Ecological's philosophy is to only support syntactically-valid Python inputs, especially if that leads to a smaller, cleaner codebase, but then I think it restricts a bit its userbase as well: programs relying on it can only be operated by users that are aware of this unusual behavior (which, as far as they are concerned, is an implementation detail). It's not a bad thing, but it leaves an empty space to be filled by e.g. another library wrapping Ecological by translating non-Pythonic user inputs. If the necessary work is small and straightforward, I believe it's simpler (from a purely logistic point of view) to do it in Ecological than building on top of it.
from ecological.
I am convinced now. Sounds like a good addition. My proposal would be:
- go with
Invalid configuration for 'TEST_HI': value 'true' is not a valid Python expression
as it does not require much work (no need to provide user with a range of valid inputs for each type) and for sure improves experience - provide new, more configurable
transform
function that can be configured to tolerate/handle things like:true/false
instead ofTrue/False
one,two,three
(comma-separated list) when PythonList
is a wanted type.
What do you think?
from ecological.
Cool! I think the cleaner error message is definitely a low-hanging and delicious fruit.
As discussed offline, I also think that transform
is the right place to extend Ecological's parsing of input values. I don't know exactly what the final result should look like, but it should be extremely easy for developers to opt-in to the more tolerant parsing (if the set of inputs recognized by the "lax" parsing is a superset of the inputs recognized by the "Python-only" parsing, as I think it should be), and I would also recommend switching the default parsing to the "lax" one in the future, while still offering the possibility for the developer to specify a custom parsing.
from ecological.
@thilp Do you maybe have more ideas what this new parser should tolerate?
from ecological.
You mentioned lists like ab,cd,ef
already, perhaps dicts on the same format (a:b,c:d,e:f
)? But it might be simpler to start with a minimal set (e.g. only the booleans) and extending it according to what users actually ask for. I almost never needed dicts in an environment variable…
from ecological.
Related Issues (15)
- Provide examples HOT 1
- Support typing.NewType
- os.environb suppport? HOT 3
- Failed if missing and/or Lazy Loading? HOT 2
- pypi / source distribution HOT 1
- Change default value handling
- Allow reading the environment when instantiating the config class
- Migrate to Poetry
- Test package both on Python 3.6 and 3.7 on CI
- Reorganize tests
- Make python 3.6.1 types optional
- Reliance on dataclasses throws errors in pip for Python3.9
- Document typing to types relationship
- Complex type hints break AutoConfig
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ecological.