Typed, extensible, dependency free configuration reader for Python projects for multiple config sources and working well in IDEs for great autocomplete performance.
MIT License
25
stars
6
forks
source link
Some syntactic-sugar suggestions for cast functions #12
I was considering contributing a couple of small additions to this project, and I wanted to run it by here first. If these seem like good ideas, I'm happy to hack on them.
Helper function for handling Enums.
If I have something like
class Fruit(Enum):
APPLE = 1
ORANGE = 2
...
it would be useful to be able to do something like
key(cast=enum_cast(Fruit))
I think the best way to do that now would be something like
key(cast=lambda x: Fruit[x] if x in Fruit.__members__ else None)
Which works but a bit awkward and verbose
Helper function for handling Lists
Support something like
key(cast=list_cast(cast_func, delimiter))
where the default value of delimiter is ","
This could just call split on the input and return the list after calling cast_func on each string element of the list.
Would love to hear anyone's thoughts on these ideas.
I was considering contributing a couple of small additions to this project, and I wanted to run it by here first. If these seem like good ideas, I'm happy to hack on them.
Helper function for handling Enums. If I have something like
it would be useful to be able to do something like
key(cast=enum_cast(Fruit))
I think the best way to do that now would be something likekey(cast=lambda x: Fruit[x] if x in Fruit.__members__ else None)
Which works but a bit awkward and verboseHelper function for handling Lists Support something like
key(cast=list_cast(cast_func, delimiter))
where the default value of delimiter is","
This could just call split on the input and return the list after callingcast_func
on each string element of the list.Would love to hear anyone's thoughts on these ideas.