Test Code: old_var = settings.TEMPLATE_DIRS settings.TEMPLATE_DIRS += ('foo',) if isinstance(settings.TEMPLATE_DIRS, tuple) else ['foo'] old_var is settings.TEMPLATE_DIRS # will return True if it was a list; will return False if it was a tuple, since a new tuple was assigned to settings.TEMPLATE_DIRS (violating the docs)
This was just a silly example, but if think of modularity and so on, this could get a disaster. The assignment could be somewhere in a helper-function where it's not obvious that the list originates from the settings. Another helper-function might use settings.TEMPLATE_DIRS to iterate over (maybe to validate all templates are reachable or something) yielding different results than the framework actual usage. Debuging this would be pretty hard (especially for those who arn't aware of the subtile differences between lists and tuples) Am Montag, 19. Januar 2015 15:49:37 UTC+1 schrieb Marc Tamlyn: > > I think Florian's point would be that you can still do: > > from django.conf import settings > settings.TEMPLATE_DIRS += ('foo',) > > if it is a tuple, so I don't really see how it being a tuple is making it > necessarily more safe than a list - is the above code really much different > to: > > from django.conf import settings > settings.TEMPLATE_DIRS.append('foo') > > On 19 January 2015 at 14:45, Andreas Kahnert <kah...@cruise-systems.com > <javascript:>> wrote: > >> I'm not talking about modifications inside the settings.py but in other >> place. With lists, unexperienced devs might do things like: from >> django.conf import settings; settings.TEMPLATE_DIRS[3] = '/my_tpls'; and >> expect to work out good. (This doesn't violate the docs, since technicaly >> settings.TEMPLATE_DIRS is still the same list, means the settings variable >> itself hasn't been changed.) This is realy just a question of logic: lists >> are mutable - settings are immutable; see the conflict? >> >> Am Montag, 19. Januar 2015 14:20:51 UTC+1 schrieb Florian Apolloner: >> >>> >>> >>> On Monday, January 19, 2015 at 12:35:10 PM UTC+1, Andreas Kahnert wrote: >>>> >>>> I'm strongly against lists. Lists are mutable objects, their components >>>> can be changed in place. The settings are initialized at server start and >>>> after that changes on them arn't reflected. Therefore all settings should >>>> be tuples from my point of view. Using a custom list/tuple class for >>>> "easy" >>>> notation within the settings.py might be an option, but after server >>>> startup all of those should be immutable. So for the sake of logic, take >>>> tuples, please. >>>> >>> >>> As long as something like settings.MY_SETTING=(1,); >>> settings.MY_SETTING+=(1,2,3) works, that argument is kinda moot imo. >>> >>> Cheers, >>> Florian >>> >> -- >> 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-develop...@googlegroups.com <javascript:>. >> To post to this group, send email to django-d...@googlegroups.com >> <javascript:>. >> Visit this group at http://groups.google.com/group/django-developers. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/django-developers/5b974048-0c9f-4ae2-8ff2-8db1fbd736f4%40googlegroups.com >> >> <https://groups.google.com/d/msgid/django-developers/5b974048-0c9f-4ae2-8ff2-8db1fbd736f4%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> >> For more options, visit https://groups.google.com/d/optout. >> > > -- 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 post to this group, send email to django-developers@googlegroups.com. Visit this group at http://groups.google.com/group/django-developers. To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/ba609be2-1f20-4a77-9692-1b95fc679117%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.