Skip to content

Commit 8719a61

Browse files
authored
Refs #22712 -- Corrected deprecation of "all" argument in django.contrib.staticfiles.finders.find().
Features deprecated in Django 5.2 should be removed in Django 6.1.
1 parent 0fdcf10 commit 8719a61

File tree

3 files changed

+23
-20
lines changed

3 files changed

+23
-20
lines changed

django/contrib/staticfiles/finders.py

+13-13
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@
99
from django.core.exceptions import ImproperlyConfigured
1010
from django.core.files.storage import FileSystemStorage, Storage, default_storage
1111
from django.utils._os import safe_join
12-
from django.utils.deprecation import RemovedInDjango60Warning
12+
from django.utils.deprecation import RemovedInDjango61Warning
1313
from django.utils.functional import LazyObject, empty
1414
from django.utils.module_loading import import_string
1515

1616
# To keep track on which directories the finder has searched the static files.
1717
searched_locations = []
1818

1919

20-
# RemovedInDjango60Warning: When the deprecation ends, remove completely.
20+
# RemovedInDjango61Warning: When the deprecation ends, remove completely.
2121
def _check_deprecated_find_param(class_name="", find_all=False, **kwargs):
2222
method_name = "find" if not class_name else f"{class_name}.find"
2323
if "all" in kwargs:
@@ -26,7 +26,7 @@ def _check_deprecated_find_param(class_name="", find_all=False, **kwargs):
2626
"Passing the `all` argument to find() is deprecated. Use `find_all` "
2727
"instead."
2828
)
29-
warnings.warn(msg, RemovedInDjango60Warning, stacklevel=2)
29+
warnings.warn(msg, RemovedInDjango61Warning, stacklevel=2)
3030

3131
# If both `find_all` and `all` were given, raise TypeError.
3232
if find_all is not False:
@@ -54,13 +54,13 @@ def check(self, **kwargs):
5454
"configured correctly."
5555
)
5656

57-
# RemovedInDjango60Warning: When the deprecation ends, remove completely.
57+
# RemovedInDjango61Warning: When the deprecation ends, remove completely.
5858
def _check_deprecated_find_param(self, **kwargs):
5959
return _check_deprecated_find_param(
6060
class_name=self.__class__.__qualname__, **kwargs
6161
)
6262

63-
# RemovedInDjango60Warning: When the deprecation ends, replace with:
63+
# RemovedInDjango61Warning: When the deprecation ends, replace with:
6464
# def find(self, path, find_all=False):
6565
def find(self, path, find_all=False, **kwargs):
6666
"""
@@ -149,13 +149,13 @@ def check(self, **kwargs):
149149
)
150150
return errors
151151

152-
# RemovedInDjango60Warning: When the deprecation ends, replace with:
152+
# RemovedInDjango61Warning: When the deprecation ends, replace with:
153153
# def find(self, path, find_all=False):
154154
def find(self, path, find_all=False, **kwargs):
155155
"""
156156
Look for files in the extra locations as defined in STATICFILES_DIRS.
157157
"""
158-
# RemovedInDjango60Warning.
158+
# RemovedInDjango61Warning.
159159
if kwargs:
160160
find_all = self._check_deprecated_find_param(find_all=find_all, **kwargs)
161161
matches = []
@@ -232,13 +232,13 @@ def list(self, ignore_patterns):
232232
for path in utils.get_files(storage, ignore_patterns):
233233
yield path, storage
234234

235-
# RemovedInDjango60Warning: When the deprecation ends, replace with:
235+
# RemovedInDjango61Warning: When the deprecation ends, replace with:
236236
# def find(self, path, find_all=False):
237237
def find(self, path, find_all=False, **kwargs):
238238
"""
239239
Look for files in the app directories.
240240
"""
241-
# RemovedInDjango60Warning.
241+
# RemovedInDjango61Warning.
242242
if kwargs:
243243
find_all = self._check_deprecated_find_param(find_all=find_all, **kwargs)
244244
matches = []
@@ -287,13 +287,13 @@ def __init__(self, storage=None, *args, **kwargs):
287287
self.storage = self.storage()
288288
super().__init__(*args, **kwargs)
289289

290-
# RemovedInDjango60Warning: When the deprecation ends, replace with:
290+
# RemovedInDjango61Warning: When the deprecation ends, replace with:
291291
# def find(self, path, find_all=False):
292292
def find(self, path, find_all=False, **kwargs):
293293
"""
294294
Look for files in the default file storage, if it's local.
295295
"""
296-
# RemovedInDjango60Warning.
296+
# RemovedInDjango61Warning.
297297
if kwargs:
298298
find_all = self._check_deprecated_find_param(find_all=find_all, **kwargs)
299299
try:
@@ -336,7 +336,7 @@ def __init__(self, *args, **kwargs):
336336
)
337337

338338

339-
# RemovedInDjango60Warning: When the deprecation ends, replace with:
339+
# RemovedInDjango61Warning: When the deprecation ends, replace with:
340340
# def find(path, find_all=False):
341341
def find(path, find_all=False, **kwargs):
342342
"""
@@ -345,7 +345,7 @@ def find(path, find_all=False, **kwargs):
345345
If ``find_all`` is ``False`` (default), return the first matching
346346
absolute path (or ``None`` if no match). Otherwise return a list.
347347
"""
348-
# RemovedInDjango60Warning.
348+
# RemovedInDjango61Warning.
349349
if kwargs:
350350
find_all = _check_deprecated_find_param(find_all=find_all, **kwargs)
351351
searched_locations[:] = []

docs/internals/deprecation.txt

+3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ about each item can often be found in the release notes of two versions prior.
1515
See the :ref:`Django 5.2 release notes <deprecated-features-5.2>` for more
1616
details on these changes.
1717

18+
* The ``all`` keyword argument of ``django.contrib.staticfiles.finders.find()``
19+
will be removed.
20+
1821
.. _deprecation-removed-in-6.0:
1922

2023
6.0

tests/staticfiles_tests/test_finders.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from django.contrib.staticfiles import finders, storage
55
from django.core.exceptions import ImproperlyConfigured
66
from django.test import SimpleTestCase, override_settings
7-
from django.utils.deprecation import RemovedInDjango60Warning
7+
from django.utils.deprecation import RemovedInDjango61Warning
88

99
from .cases import StaticFilesTestCase
1010
from .settings import TEST_ROOT
@@ -37,7 +37,7 @@ def test_find_all(self):
3737

3838
def test_find_all_deprecated_param(self):
3939
src, dst = self.find_all
40-
with self.assertWarnsMessage(RemovedInDjango60Warning, DEPRECATION_MSG):
40+
with self.assertWarnsMessage(RemovedInDjango61Warning, DEPRECATION_MSG):
4141
found = self.finder.find(src, all=True)
4242
found = [os.path.normcase(f) for f in found]
4343
dst = [os.path.normcase(d) for d in dst]
@@ -50,7 +50,7 @@ def test_find_all_conflicting_params(self):
5050
"argument 'find_all'"
5151
)
5252
with (
53-
self.assertWarnsMessage(RemovedInDjango60Warning, DEPRECATION_MSG),
53+
self.assertWarnsMessage(RemovedInDjango61Warning, DEPRECATION_MSG),
5454
self.assertRaisesMessage(TypeError, msg),
5555
):
5656
self.finder.find(src, find_all=True, all=True)
@@ -62,7 +62,7 @@ def test_find_all_unexpected_params(self):
6262
"argument 'wrong'"
6363
)
6464
with (
65-
self.assertWarnsMessage(RemovedInDjango60Warning, DEPRECATION_MSG),
65+
self.assertWarnsMessage(RemovedInDjango61Warning, DEPRECATION_MSG),
6666
self.assertRaisesMessage(TypeError, msg),
6767
):
6868
self.finder.find(src, all=True, wrong=1)
@@ -165,7 +165,7 @@ def test_searched_locations_find_all(self):
165165
)
166166

167167
def test_searched_locations_deprecated_all(self):
168-
with self.assertWarnsMessage(RemovedInDjango60Warning, DEPRECATION_MSG):
168+
with self.assertWarnsMessage(RemovedInDjango61Warning, DEPRECATION_MSG):
169169
finders.find("spam", all=True)
170170
self.assertEqual(
171171
finders.searched_locations,
@@ -175,15 +175,15 @@ def test_searched_locations_deprecated_all(self):
175175
def test_searched_locations_conflicting_params(self):
176176
msg = "find() got multiple values for argument 'find_all'"
177177
with (
178-
self.assertWarnsMessage(RemovedInDjango60Warning, DEPRECATION_MSG),
178+
self.assertWarnsMessage(RemovedInDjango61Warning, DEPRECATION_MSG),
179179
self.assertRaisesMessage(TypeError, msg),
180180
):
181181
finders.find("spam", find_all=True, all=True)
182182

183183
def test_searched_locations_unexpected_params(self):
184184
msg = "find() got an unexpected keyword argument 'wrong'"
185185
with (
186-
self.assertWarnsMessage(RemovedInDjango60Warning, DEPRECATION_MSG),
186+
self.assertWarnsMessage(RemovedInDjango61Warning, DEPRECATION_MSG),
187187
self.assertRaisesMessage(TypeError, msg),
188188
):
189189
finders.find("spam", all=True, wrong=1)

0 commit comments

Comments
 (0)