File: test_helpers.yml

package info (click to toggle)
python-django-stubs 5.2.9-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,832 kB
  • sloc: python: 5,185; makefile: 15; sh: 8
file content (66 lines) | stat: -rw-r--r-- 2,947 bytes parent folder | download
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
-   case: transaction_atomic_contextmanager
    main: |
        from django.db import transaction
        with transaction.atomic():
            pass
        with transaction.atomic(using="mydb"):
            pass
        with transaction.atomic(using="mydb", savepoint=False):
            pass
        with transaction.atomic(using="mydb", savepoint=False, durable=True):
            pass

-   case: transaction_atomic_decorator
    main: |
        from typing_extensions import reveal_type
        from django.db import transaction

        @transaction.atomic()
        def decorated_func(param1: str, param2: int) -> bool:
            pass
        # Ensure that the function's type is preserved
        reveal_type(decorated_func)  # N: Revealed type is "def (param1: builtins.str, param2: builtins.int) -> builtins.bool"

        @transaction.atomic(using="mydb")
        def decorated_func_using(param1: str, param2: int) -> bool:
            pass
        # Ensure that the function's type is preserved
        reveal_type(decorated_func_using)  # N: Revealed type is "def (param1: builtins.str, param2: builtins.int) -> builtins.bool"

        class ClassWithAtomicMethod:
            # Bare decorator
            @transaction.atomic
            def atomic_method1(self, abc: int) -> str:
                pass
            @transaction.atomic(savepoint=True)
            def atomic_method2(self) -> None:
                pass
            @transaction.atomic(using="db", savepoint=True)
            def atomic_method3(self, myparam: str) -> int:
                pass
        ClassWithAtomicMethod().atomic_method1("abc") # E: Argument 1 to "atomic_method1" of "ClassWithAtomicMethod" has incompatible type "str"; expected "int"  [arg-type]
        # Ensure that the method's type is preserved
        reveal_type(ClassWithAtomicMethod().atomic_method1) # N: Revealed type is "def (abc: builtins.int) -> builtins.str"
        # Ensure that the method's type is preserved
        reveal_type(ClassWithAtomicMethod().atomic_method3) # N: Revealed type is "def (myparam: builtins.str) -> builtins.int"


-   case: mark_safe_decorator_and_function
    main: |
        from typing_extensions import reveal_type
        from django.utils.safestring import mark_safe
        s = 'hello'
        reveal_type(mark_safe(s))  # N: Revealed type is "django.utils.safestring.SafeString"
        reveal_type(mark_safe(s) + mark_safe(s))  # N: Revealed type is "django.utils.safestring.SafeString"
        reveal_type(s + mark_safe(s))  # N: Revealed type is "builtins.str"

        s += mark_safe(s)
        reveal_type(s)  # N: Revealed type is "builtins.str"
        ms = mark_safe(s)
        ms += mark_safe(s)
        reveal_type(ms)  # N: Revealed type is "django.utils.safestring.SafeString"

        @mark_safe
        def func(s: str) -> str:
            pass
        reveal_type(func)  # N: Revealed type is "def (s: builtins.str) -> builtins.str"