Hello,

I’m about to introduce a new setting that is a sequence of things, TEMPLATES, 
and I have to decide whether it will be a tuple of a list.

Unfortunately Django is very inconsistent in the type of settings. In 
global_settings.py:

- 22 settings are tuples
        - 10 are empty, 12 aren't
        - 12 are referred to as “lists” in code comments, 1 as “tuple”
- 6 settings are lists
        - all of them are empty

Even the tutorial is inconsistent. The first two settings described are:

- INSTALLED_APPS: example is a tuple
- TEMPLATE_DIRS: example is a list

It would be nice to standardize on tuples or lists — at least for new code if 
it’s undesirable to change the existing code.

This is purely a matter of consistency and aesthetics. Using a tuple or a list 
never makes any difference in the code.

While lists are less common than tuples currently, I prefer them for two 
reasons:

1) All these settings are sequences of similar things. Such values are best 
represented with lists, unless they have to be immutable, in which case a tuple 
can be used. (tuples are both “namedtuples without names” and “immutable lists” 
in Python.)

2) Lists aren’t prone to the “missing comma in single-item tuple” problem which 
bites beginners and experienced pythonistas alike. Django even has code to 
defend against this mistake for a handful of settings. Search for 
“tuple_settings” in the source.

Surprisingly, it seems that there isn’t a backwards compatibility problem with 
changing the type to lists, as the following pattern still works:

# myproject/settings.py
from django.conf.global_settings import FILE_UPLOAD_HANDLERS
FILE_UPLOAD_HANDLERS += ('myproject.uploadhandler.FooBarUploadHandler',)

Proof:

>>> foo = ['abc']
>>> foo += ('def',)
>>> foo
['abc', ‘def’]

I can’t think of another circumstance it which the type of the default value 
will make a difference.

So… can we normalize the code and satisfy my OCD? Or should I just stop caring 
and move on? ;-)

-- 
Aymeric.



-- 
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/6840953C-B5CA-4575-BBA1-90CD9E880C58%40polytechnique.org.
For more options, visit https://groups.google.com/d/optout.

Reply via email to