1
0
mirror of https://github.com/django/django.git synced 2024-12-22 17:16:24 +00:00

Refs #23919 -- Stopped inheriting from object to define new style classes.

Tests and docs complement to cecc079168.
This commit is contained in:
Mariusz Felisiak 2017-06-26 16:30:31 +02:00 committed by Tim Graham
parent fba0eaa5d6
commit 081e787160
18 changed files with 24 additions and 24 deletions

View File

@ -36,7 +36,7 @@ You only need to know that 52 cards are dealt out equally to four players, who
are traditionally called *north*, *east*, *south* and *west*. Our class looks
something like this::
class Hand(object):
class Hand:
"""A hand of cards (bridge style)"""
def __init__(self, north, east, south, west):

View File

@ -71,7 +71,7 @@ the assembly and transmission of a large CSV file::
from django.http import StreamingHttpResponse
class Echo(object):
class Echo:
"""An object that implements just the write method of the file-like
interface.
"""

View File

@ -42,7 +42,7 @@ method of database routers as ``**hints``:
.. snippet::
:filename: myapp/dbrouters.py
class MyRouter(object):
class MyRouter:
def allow_migrate(self, db, app_label, model_name=None, **hints):
if 'target_db' in hints:

View File

@ -151,7 +151,7 @@ Imports
CONSTANT = 'foo'
class Example(object):
class Example:
# ...
* Use convenience imports whenever available. For example, do this::

View File

@ -427,7 +427,7 @@ Navigate to the ``django/django/forms/`` folder and open the ``forms.py`` file.
Find the ``BaseForm`` class on line 72 and add the ``prefix`` class attribute
right after the ``field_order`` attribute::
class BaseForm(object):
class BaseForm:
# This is the main implementation of all the Form logic. Note that this
# class is different than Form. See the comments by the Form class for
# more information. Any improvements to the form API should be made to
@ -529,7 +529,7 @@ Use the arrow keys to move up and down.
index 509709f..d1370de 100644
--- a/django/forms/forms.py
+++ b/django/forms/forms.py
@@ -75,6 +75,7 @@ class BaseForm(object):
@@ -75,6 +75,7 @@ class BaseForm:
# information. Any improvements to the form API should be made to *this*
# class, not to the Form class.
field_order = None
@ -537,7 +537,7 @@ Use the arrow keys to move up and down.
def __init__(self, data=None, files=None, auto_id='id_%s', prefix=None,
initial=None, error_class=ErrorList, label_suffix=None,
@@ -83,7 +84,8 @@ class BaseForm(object):
@@ -83,7 +84,8 @@ class BaseForm:
self.data = data or {}
self.files = files or {}
self.auto_id = auto_id

View File

@ -100,14 +100,14 @@ and returns a user object.
The ``authenticate`` method takes a ``request`` argument and credentials as
keyword arguments. Most of the time, it'll just look like this::
class MyBackend(object):
class MyBackend:
def authenticate(self, request, username=None, password=None):
# Check the username/password and return a user.
...
But it could also authenticate a token, like so::
class MyBackend(object):
class MyBackend:
def authenticate(self, request, token=None):
# Check the token and return a user.
...
@ -135,7 +135,7 @@ object the first time a user authenticates::
from django.contrib.auth.hashers import check_password
from django.contrib.auth.models import User
class SettingsBackend(object):
class SettingsBackend:
"""
Authenticate against the settings ADMIN_LOGIN and ADMIN_PASSWORD.
@ -198,7 +198,7 @@ will immediately fail and Django won't check the backends that follow.
The simple backend above could implement permissions for the magic admin
fairly simply::
class SettingsBackend(object):
class SettingsBackend:
...
def has_perm(self, user_obj, perm, obj=None):
return user_obj.username == settings.ADMIN_LOGIN

View File

@ -648,7 +648,7 @@ Here's a basic example of a validator, with one optional setting::
from django.core.exceptions import ValidationError
from django.utils.translation import gettext as _
class MinimumLengthValidator(object):
class MinimumLengthValidator:
def __init__(self, min_length=8):
self.min_length = min_length

View File

@ -238,7 +238,7 @@ operations to ``cache_replica``, and all write operations to
``cache_primary``. The cache table will only be synchronized onto
``cache_primary``::
class CacheRouter(object):
class CacheRouter:
"""A router to control all database cache operations"""
def db_for_read(self, model, **hints):

View File

@ -233,7 +233,7 @@ works for AJAX requests as well as 'normal' form POSTs::
from django.views.generic.edit import CreateView
from myapp.models import Author
class AjaxableResponseMixin(object):
class AjaxableResponseMixin:
"""
Mixin to add AJAX support to a form.
Must be used with an object-based FormView (e.g. CreateView)

View File

@ -603,7 +603,7 @@ For example, a simple JSON mixin might look something like this::
from django.http import JsonResponse
class JSONResponseMixin(object):
class JSONResponseMixin:
"""
A mixin that can be used to render a JSON response.
"""

View File

@ -295,7 +295,7 @@ databases::
Now we'll need to handle routing. First we want a router that knows to
send queries for the ``auth`` app to ``auth_db``::
class AuthRouter(object):
class AuthRouter:
"""
A router to control all database operations on models in the
auth application.
@ -340,7 +340,7 @@ from::
import random
class PrimaryReplicaRouter(object):
class PrimaryReplicaRouter:
def db_for_read(self, model, **hints):
"""
Reads go to a randomly-chosen replica.

View File

@ -43,7 +43,7 @@ A middleware can be written as a function that looks like this::
Or it can be written as a class whose instances are callable, like this::
class SimpleMiddleware(object):
class SimpleMiddleware:
def __init__(self, get_response):
self.get_response = get_response
# One-time configuration and initialization.

View File

@ -717,7 +717,7 @@ serializable, you can use the ``@deconstructible`` class decorator from
from django.utils.deconstruct import deconstructible
@deconstructible
class MyCustomClass(object):
class MyCustomClass:
def __init__(self, foo=1):
self.foo = foo

View File

@ -243,7 +243,7 @@ arguments as you like.
For example, here's how sending our ``pizza_done`` signal might look::
class PizzaStore(object):
class PizzaStore:
...
def send_pizza(self, toppings, size):

View File

@ -531,7 +531,7 @@ fictional ``foobar`` template library::
raise TemplateSyntaxError(exc.args)
class Template(object):
class Template:
def __init__(self, template):
self.template = template

View File

@ -122,7 +122,7 @@ class ForeignKeyNameTests(IndexNameTests):
)
class MockReference(object):
class MockReference:
def __init__(self, representation, referenced_tables, referenced_columns):
self.representation = representation
self.referenced_tables = referenced_tables

View File

@ -40,7 +40,7 @@ class Money(decimal.Decimal):
)
class TestModel1(object):
class TestModel1:
def upload_to(self):
return '/somewhere/dynamic/'
thing = models.FileField(upload_to=upload_to)

View File

@ -9,7 +9,7 @@ class Relation(models.Model):
pass
class InstanceOnlyDescriptor(object):
class InstanceOnlyDescriptor:
def __get__(self, instance, cls=None):
if instance is None:
raise AttributeError('Instance only')