From ed4bfacb3c942d0d32795e1a733b1b9367afd2e9 Mon Sep 17 00:00:00 2001 From: Nick Pope Date: Wed, 22 Aug 2018 19:40:14 +0100 Subject: [PATCH] Fixed #29703 -- Deprecated QuerySetPaginator alias. Unused since 4406d283e13819b04556df21044089b7d119edb0. --- django/core/paginator.py | 10 +++++++++- docs/internals/deprecation.txt | 2 ++ docs/releases/2.2.txt | 3 +++ tests/pagination/tests.py | 9 ++++++++- 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/django/core/paginator.py b/django/core/paginator.py index d48a244a44..d484c31ed5 100644 --- a/django/core/paginator.py +++ b/django/core/paginator.py @@ -3,6 +3,7 @@ import inspect import warnings from math import ceil +from django.utils.deprecation import RemovedInDjango31Warning from django.utils.functional import cached_property from django.utils.inspect import method_has_no_args from django.utils.translation import gettext_lazy as _ @@ -125,7 +126,14 @@ class Paginator: ) -QuerySetPaginator = Paginator # For backwards-compatibility. +class QuerySetPaginator(Paginator): + + def __init__(self, *args, **kwargs): + warnings.warn( + 'The QuerySetPaginator alias of Paginator is deprecated.', + RemovedInDjango31Warning, stacklevel=2, + ) + super().__init__(*args, **kwargs) class Page(collections.abc.Sequence): diff --git a/docs/internals/deprecation.txt b/docs/internals/deprecation.txt index 6d8ff36835..d7b02fa3bc 100644 --- a/docs/internals/deprecation.txt +++ b/docs/internals/deprecation.txt @@ -17,6 +17,8 @@ details on these changes. * ``django.utils.timezone.FixedOffset`` will be removed. +* ``django.core.paginator.QuerySetPaginator`` will be removed. + .. _deprecation-removed-in-3.0: 3.0 diff --git a/docs/releases/2.2.txt b/docs/releases/2.2.txt index ff692151ed..5881265cbf 100644 --- a/docs/releases/2.2.txt +++ b/docs/releases/2.2.txt @@ -293,3 +293,6 @@ Miscellaneous * ``django.utils.timezone.FixedOffset`` is deprecated in favor of :class:`datetime.timezone`. + +* The undocumented ``QuerySetPaginator`` alias of + ``django.core.paginator.Paginator`` is deprecated. diff --git a/tests/pagination/tests.py b/tests/pagination/tests.py index 8ab04940ab..20e74981cd 100644 --- a/tests/pagination/tests.py +++ b/tests/pagination/tests.py @@ -2,10 +2,11 @@ import warnings from datetime import datetime from django.core.paginator import ( - EmptyPage, InvalidPage, PageNotAnInteger, Paginator, + EmptyPage, InvalidPage, PageNotAnInteger, Paginator, QuerySetPaginator, UnorderedObjectListWarning, ) from django.test import SimpleTestCase, TestCase +from django.utils.deprecation import RemovedInDjango31Warning from .custom import ValidAdjacentNumsPaginator from .models import Article @@ -297,6 +298,12 @@ class PaginationTests(SimpleTestCase): with self.assertRaises(EmptyPage): paginator.get_page(1) + def test_querysetpaginator_deprecation(self): + msg = 'The QuerySetPaginator alias of Paginator is deprecated.' + with self.assertWarnsMessage(RemovedInDjango31Warning, msg) as cm: + QuerySetPaginator([], 1) + self.assertEqual(cm.filename, __file__) + class ModelPaginationTests(TestCase): """