From f970a98e464320c09dde8d45009eadfb4d038a57 Mon Sep 17 00:00:00 2001 From: zhengkangyang <1872483761@qq.com> Date: Sat, 6 Jun 2026 16:17:24 +0800 Subject: Fixed #37142 -- Moved django_file_prefixes() to django.utils.warnings. --- .../writing-code/submitting-patches.txt | 3 ++- docs/ref/utils.txt | 28 ++++++++++++++++++++++ docs/releases/6.2.txt | 5 +++- 3 files changed, 34 insertions(+), 2 deletions(-) (limited to 'docs') diff --git a/docs/internals/contributing/writing-code/submitting-patches.txt b/docs/internals/contributing/writing-code/submitting-patches.txt index 288a50fc76..a038de53f7 100644 --- a/docs/internals/contributing/writing-code/submitting-patches.txt +++ b/docs/internals/contributing/writing-code/submitting-patches.txt @@ -352,7 +352,8 @@ previous behavior, or standalone items that are unnecessary or unused when the deprecation ends. For example:: import warnings - from django.utils.deprecation import RemovedInDjangoXXWarning, django_file_prefixes + from django.utils.deprecation import RemovedInDjangoXXWarning + from django.utils.warnings import django_file_prefixes # RemovedInDjangoXXWarning. diff --git a/docs/ref/utils.txt b/docs/ref/utils.txt index 1c42784d13..0f38105713 100644 --- a/docs/ref/utils.txt +++ b/docs/ref/utils.txt @@ -1187,3 +1187,31 @@ For a complete discussion on the usage of the following see the Turns a Django template into something that is understood by ``xgettext``. It does so by translating the Django translation tags into standard ``gettext`` function invocations. + +``django.utils.warnings`` +========================= + +.. module:: django.utils.warnings + :synopsis: Helpers for issuing warnings. + +.. function:: django_file_prefixes() + + .. versionadded:: 6.2 + + Returns a tuple of file path prefixes for the Django package directory. + This is used as the ``skip_file_prefixes`` argument to + :func:`warnings.warn` so that warnings are attributed to the *caller* + (your project or third-party library) rather than to Django internals. + + The result is cached after the first call. + + Usage example:: + + import warnings + from django.utils.warnings import django_file_prefixes + + warnings.warn( + "Your custom warning message.", + category=RuntimeWarning, + skip_file_prefixes=django_file_prefixes(), + ) diff --git a/docs/releases/6.2.txt b/docs/releases/6.2.txt index 09dab3a93d..74ba31f171 100644 --- a/docs/releases/6.2.txt +++ b/docs/releases/6.2.txt @@ -232,7 +232,10 @@ URLs Utilities ~~~~~~~~~ -* ... +* The new ``django.utils.warnings`` module provides + :func:`~django.utils.warnings.django_file_prefixes`, which returns the file + path prefix of the Django package for use as the ``skip_file_prefixes`` + argument of :func:`warnings.warn`. Validators ~~~~~~~~~~ -- cgit v1.3