I am bit curious to know why Django 1.9 replaced tuples () with lists [] in settings, URLs and other configuration files
I just upgraded to Django 1.9 and noticed these changes. What is the logic behind them?
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles'
]
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static'),
]
urls.py
urlpatterns = [
url(r'^', admin.site.urls),
]
Is anything different because of these changes?
It is explained in issue #8846 (emphasis mine):
Also see this answer for a more up-to-date discussion.
Another answer (not directly related to this issue) demonstrates that accessing elements is actually faster with a
list
.Update and further information: It is correct that the above issue was closed years ago, but I included it because it explained the rationale behind the decision and many similar discussions refer to the same ticket. The actual implementation decision was triggered after the following discussion on django-developers started by core Django developer Aymeric Augustin:
And the switch to lists actually happened in issue #24149 which also referred to the above discussion.
In the release notes of 1.9, there is:
So it appears that it was just done for consistency. Both tuples and lists should work fine. If you use a tuple with 1 element, remember the comma
(1,)
because otherwise it's not a tuple but simply an expression in parens.As for urlpatterns, those used to be defined using a
patterns()
function, but that was deprecated in Django 1.8, as a list of url instances works fine. As the function will be removed in the future, it shouldn't be used in new apps and projects.