Hi Andreas,
I agree that tuples do slightly help enforce that settings are supposed to
be immutable, and I agree that if someone were to try to modify the
settings the way you showed it would be very hard to debug. However, I
think it's a pretty rare case.
I think a much more common case is the trailing comma problem with single
element tuples. This can also be very frustrating for beginners. I'd
personally rather help out the beginner cases than someone attempting to do
things that they shouldn't be doing.
I also think lists of tuples are easier to read than tuples of tuples.
Anyone could still use tuples in their settings if they want the extra
strength.
What do you think?
Collin
On Monday, January 19, 2015 at 10:05:46 AM UTC-5, Andreas Kahnert wrote:
>
> 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 <[email protected]>
>> 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 [email protected].
>>> To post to this group, send email to [email protected].
>>> 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 [email protected].
To post to this group, send email to [email protected].
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/e003c6b4-ea5b-470c-bf0f-30ec115bb5c3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.