summaryrefslogtreecommitdiff
path: root/tests/deprecation/internal.py
blob: 893a05d002fec8e7ad308094262a9ce2306e6eb2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# Simulated Django "internals" for WarnAboutExternalUseTests.
#
# Every function in this module ends up calling deprecated_function(), which
# calls warn_about_external_use(). The other functions provide various stack
# depths and qualnames for test purposes. All functions pass their arguments
# through to warn_about_external_use().
#
# The tests set internal_modules to treat this module (only) as the "internal"
# Django code. Pass internal_modules=None for the original default behavior or
# internal_modules=tuple(...) to make some other modules "internal."

from django.utils.deprecation import (
    RemovedAfterNextVersionWarning,
    RemovedInNextVersionWarning,
    deprecate_posargs,
    warn_about_external_use,
)


def deprecated_function(message=None, category=None, **kwargs):
    kwargs.setdefault("internal_modules", (__name__,))
    warn_about_external_use(
        message or "Message",
        category or RemovedInNextVersionWarning,
        **kwargs,
    )


def one_indirection(*args, **kwargs):
    deprecated_function(*args, **kwargs)


def two_indirections(*args, **kwargs):
    one_indirection(*args, **kwargs)


def three_indirections(*args, **kwargs):
    two_indirections(*args, **kwargs)


class Class:
    def deprecated_method(self, *args, **kwargs):
        deprecated_function(*args, **kwargs)

    def one_indirection(self, *args, **kwargs):
        self.deprecated_method(*args, **kwargs)

    def two_indirections(self, *args, **kwargs):
        self.one_indirection(*args, **kwargs)


@deprecate_posargs(RemovedAfterNextVersionWarning, ["a"])
def decorated(message=None, category=None, *, a=None, **kwargs):
    deprecated_function(message, category, **kwargs)


def call_decorated(*args, **kwargs):
    decorated(*args, **kwargs)


def nested(*args, **kwargs):
    # inner.__qualname__ is something like "nested.<locals>.inner".
    def inner(*args, **kwargs):
        deprecated_function(*args, **kwargs)

    inner(*args, **kwargs)