Comments (3)
That's a great idea. We can support both actually. If source
is provided on class then it overrides the settings on Variable
.
However in this case (when source would be os.environb
) my thinking is it is undesirable to have it globally because it would be very painful for user to convert from bytes
to str
for example:
# Given that the transform func on Variable is the default cast
>>> from ecological import config
>>> config.cast(b'My value', str)
"b'My value'"
So suddenly all strings become screwed when you switch globally to os.environb
and then you would new to explictly use Variable
on each of them to do some other transform.
from ecological.
For me it sounds like really easy change that can be implemented in a very generic, useful way.
First introduce a concept of source
on Variable
class and pass it as the constructor parameter; the protocol here would be source
is a dictionary that Variable
reads values from where os.environ
stays the default one. Then utilizing os.environb
would be trivial from user POV:
class Configuration(ecological.AutoConfig):
my_var1: str = ecological.Variable("my_var1", source=os.environb)
from ecological.
Would there be a way to also specify source
as "class argument", just like prefix
? (I think you would have all your values coming from the same dict much more often than from different dicts.)
from ecological.
Related Issues (15)
- Provide examples HOT 1
- Change default value handling
- Make python 3.6.1 types optional
- Document typing to types relationship
- Complex type hints break AutoConfig
- Support typing.NewType
- Failed if missing and/or Lazy Loading? HOT 2
- pypi / source distribution HOT 1
- Allow reading the environment when instantiating the config class
- Migrate to Poetry
- Test package both on Python 3.6 and 3.7 on CI
- Better support for boolean values HOT 9
- Reorganize tests
- Reliance on dataclasses throws errors in pip for Python3.9
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.