At Florian's suggestion in another thread, I propose that we move further discussion of the settings refactor to the forum: https://forum.djangoproject.com/t/settings-refactor/17352
On Wednesday, November 2, 2022 at 2:58:29 PM UTC-4 f.apo...@gmail.com wrote: > The speckenv example highlights the problems when using `literal_eval`: > A=[] will parse as list but A=[a] will parse as string again (if I read the > code correctly). This ambiguity makes it really hard to explain. When using > `literal_eval` one imo has to be consistent and don't fall back to a str > and require strings to be written as A='[]' (with quotes). Then again this > is rather ugly and hard to get right/explain if you try to pass that in via > a shell ala `A='[]' django-admin runserver` and now A is a list again :/ > > Cheers, > Florian > > On Wednesday, November 2, 2022 at 8:20:00 AM UTC+1 m...@feinheit.ch wrote: > >> On Tue, Nov 1, 2022 at 10:34 AM Florian Apolloner <f.apo...@gmail.com> >> wrote: >> >>> Right, that would work. I am wondering though if we want to go all in on >>> a typed config object like that or in a first step only have a simple API >>> like `config.get('DEBUG', cast=bool)`. >>> >>> >> I found a neat trick in a 12factor library somewhere (I don't remember >> where unfortunately) of using ast.literal_eval for config variables: >> https://docs.python.org/3/library/ast.html#ast.literal_eval >> >> https://github.com/matthiask/speckenv/blob/94722bcc95b94a9e6b1a1aada2bd977c43bfb767/speckenv.py#L63 >> >> This may be too cute or magical for Django. It certainly works well and >> avoids having to be overspecific with types. I find it boring to tell the >> config loader that True is a bool and "hello" is a string. That being said >> I don't really have a strong preference here apart from having a strong >> dislike for the "several settings files" pattern. It's much more obvious to >> me if e.g. `MIDDLEWARE` is configured in a single location and not modified >> in other files. >> >> Thanks, >> Matthias >> >> >> >> -- You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-developers+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/3c783c4b-13ec-4e23-9fe1-101b92e4c49bn%40googlegroups.com.