bwindsor / typed-config

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

Closed jonmooser closed 1 year ago

jonmooser commented 1 year ago

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.

  1. 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

  2. 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.

bwindsor commented 1 year ago

Closed by #14 and #15