summaryrefslogtreecommitdiff
path: root/docs/internals/contributing/writing-code
diff options
context:
space:
mode:
authordjango-bot <ops@djangoproject.com>2023-02-28 20:53:28 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2023-03-01 13:03:56 +0100
commit14459f80ee3a9e005989db37c26fd13bb6d2fab2 (patch)
treeeb62429ed696ed3a5389f3a676aecfc6d15a99cc /docs/internals/contributing/writing-code
parent6015bab80e28aef2669f6fac53423aa65f70cb08 (diff)
Fixed #34140 -- Reformatted code blocks in docs with blacken-docs.
Diffstat (limited to 'docs/internals/contributing/writing-code')
-rw-r--r--docs/internals/contributing/writing-code/coding-style.txt40
-rw-r--r--docs/internals/contributing/writing-code/submitting-patches.txt5
-rw-r--r--docs/internals/contributing/writing-code/unit-tests.txt10
3 files changed, 33 insertions, 22 deletions
diff --git a/docs/internals/contributing/writing-code/coding-style.txt b/docs/internals/contributing/writing-code/coding-style.txt
index ca94eaa1fc..5b64e94b24 100644
--- a/docs/internals/contributing/writing-code/coding-style.txt
+++ b/docs/internals/contributing/writing-code/coding-style.txt
@@ -68,20 +68,20 @@ Python style
guide, f-strings should use only plain variable and property access, with
prior local variable assignment for more complex cases::
- # Allowed
- f'hello {user}'
- f'hello {user.name}'
- f'hello {self.user.name}'
+ # Allowed
+ f"hello {user}"
+ f"hello {user.name}"
+ f"hello {self.user.name}"
# Disallowed
- f'hello {get_user()}'
- f'you are {user.age * 365.25} days old'
+ f"hello {get_user()}"
+ f"you are {user.age * 365.25} days old"
# Allowed with local variable assignment
user = get_user()
- f'hello {user}'
+ f"hello {user}"
user_days_old = user.age * 365.25
- f'you are {user_days_old} days old'
+ f"you are {user_days_old} days old"
f-strings should not be used for any string that may require translation,
including error and logging messages. In general ``format()`` is more
@@ -182,7 +182,10 @@ Imports
# Django
from django.http import Http404
from django.http.response import (
- Http404, HttpResponse, HttpResponseNotAllowed, StreamingHttpResponse,
+ Http404,
+ HttpResponse,
+ HttpResponseNotAllowed,
+ StreamingHttpResponse,
cookie,
)
@@ -195,7 +198,7 @@ Imports
except ImportError:
yaml = None
- CONSTANT = 'foo'
+ CONSTANT = "foo"
class Example:
@@ -272,21 +275,22 @@ Model style
last_name = models.CharField(max_length=40)
class Meta:
- verbose_name_plural = 'people'
+ verbose_name_plural = "people"
Don't do this::
class Person(models.Model):
first_name = models.CharField(max_length=20)
last_name = models.CharField(max_length=40)
+
class Meta:
- verbose_name_plural = 'people'
+ verbose_name_plural = "people"
Don't do this, either::
class Person(models.Model):
class Meta:
- verbose_name_plural = 'people'
+ verbose_name_plural = "people"
first_name = models.CharField(max_length=20)
last_name = models.CharField(max_length=40)
@@ -307,11 +311,11 @@ Model style
Example::
class MyModel(models.Model):
- DIRECTION_UP = 'U'
- DIRECTION_DOWN = 'D'
+ DIRECTION_UP = "U"
+ DIRECTION_DOWN = "D"
DIRECTION_CHOICES = [
- (DIRECTION_UP, 'Up'),
- (DIRECTION_DOWN, 'Down'),
+ (DIRECTION_UP, "Up"),
+ (DIRECTION_DOWN, "Down"),
]
Use of ``django.conf.settings``
@@ -327,7 +331,7 @@ as follows::
from django.conf import settings
- settings.configure({}, SOME_SETTING='foo')
+ settings.configure({}, SOME_SETTING="foo")
However, if any setting is accessed before the ``settings.configure`` line,
this will not work. (Internally, ``settings`` is a ``LazyObject`` which
diff --git a/docs/internals/contributing/writing-code/submitting-patches.txt b/docs/internals/contributing/writing-code/submitting-patches.txt
index 14cb2ef2fa..8ef5c1da54 100644
--- a/docs/internals/contributing/writing-code/submitting-patches.txt
+++ b/docs/internals/contributing/writing-code/submitting-patches.txt
@@ -186,6 +186,7 @@ level:
from django.test import ignore_warnings
from django.utils.deprecation import RemovedInDjangoXXWarning
+
@ignore_warnings(category=RemovedInDjangoXXWarning)
def test_foo(self):
...
@@ -195,6 +196,7 @@ level:
from django.test import ignore_warnings
from django.utils.deprecation import RemovedInDjangoXXWarning
+
@ignore_warnings(category=RemovedInDjangoXXWarning)
class MyDeprecatedTests(unittest.TestCase):
...
@@ -203,8 +205,9 @@ You can also add a test for the deprecation warning::
from django.utils.deprecation import RemovedInDjangoXXWarning
+
def test_foo_deprecation_warning(self):
- msg = 'Expected deprecation message'
+ msg = "Expected deprecation message"
with self.assertWarnsMessage(RemovedInDjangoXXWarning, msg):
# invoke deprecated behavior
...
diff --git a/docs/internals/contributing/writing-code/unit-tests.txt b/docs/internals/contributing/writing-code/unit-tests.txt
index 8789e0ef7b..40fb2ec221 100644
--- a/docs/internals/contributing/writing-code/unit-tests.txt
+++ b/docs/internals/contributing/writing-code/unit-tests.txt
@@ -537,11 +537,13 @@ a temporary ``Apps`` instance. To do this, use the
from django.test import SimpleTestCase
from django.test.utils import isolate_apps
+
class TestModelDefinition(SimpleTestCase):
- @isolate_apps('app_label')
+ @isolate_apps("app_label")
def test_model_definition(self):
class TestModel(models.Model):
pass
+
...
.. admonition:: Setting ``app_label``
@@ -561,8 +563,9 @@ a temporary ``Apps`` instance. To do this, use the
from django.test import SimpleTestCase
from django.test.utils import isolate_apps
+
class TestModelDefinition(SimpleTestCase):
- @isolate_apps('app_label', 'other_app_label')
+ @isolate_apps("app_label", "other_app_label")
def test_model_definition(self):
# This model automatically receives app_label='app_label'
class TestModel(models.Model):
@@ -570,5 +573,6 @@ a temporary ``Apps`` instance. To do this, use the
class OtherAppModel(models.Model):
class Meta:
- app_label = 'other_app_label'
+ app_label = "other_app_label"
+
...