File: test_functional.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 (85 lines) | stat: -rw-r--r-- 3,419 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
-   case: cached_property_class_vs_instance_attributes
    main: |
      from django.utils.functional import cached_property
      from typing import ClassVar
      from typing_extensions import reveal_type

      class Foo:
          @cached_property
          def attr(self) -> list[str]: ...

          @cached_property  # E: Too many arguments for property  [misc]
          def attr2(self, arg2: str) -> list[str]: ...

          reveal_type(attr)  # N: Revealed type is "def (self: main.Foo) -> builtins.list[builtins.str]"

      reveal_type(Foo.attr)  # N: Revealed type is "def (self: main.Foo) -> builtins.list[builtins.str]"

      f = Foo()
      reveal_type(f.attr)  # N: Revealed type is "builtins.list[builtins.str]"
      f.attr.func  # E: "list[str]" has no attribute "func"  [attr-defined]

      # May be overridden by @property
      class Bar(Foo):
          @property
          def attr(self) -> list[str]: ...

      # May be overridden by ClassVar
      class Quux(Foo):
          attr: ClassVar[list[str]] = []

      # ClassVar may not be overridden by cached_property
      class Baz(Quux):
          @cached_property
          def attr(self) -> list[str]: ...  # E: Cannot override writeable attribute with read-only property  [override]

-   case: str_promise_proxy
    main:  |
      from typing_extensions import reveal_type
      from django.utils.functional import Promise, lazystr, _StrPromise

      s = lazystr("asd")

      reveal_type(s)                 # N: Revealed type is "django.utils.functional._StrPromise"

      reveal_type(s.format("asd"))   # N: Revealed type is "builtins.str"
      reveal_type(s.capitalize())    # N: Revealed type is "builtins.str"
      reveal_type(s.swapcase)        # N: Revealed type is "def () -> builtins.str"
      reveal_type(s.__getnewargs__)  # N: Revealed type is "def () -> tuple[builtins.str]"
      s.nonsense                     # E: "_StrPromise" has no attribute "nonsense"  [attr-defined]
      f: _StrPromise | str
      reveal_type(f.format("asd"))   # N: Revealed type is "builtins.str"
      reveal_type(f + "asd")         # N: Revealed type is "builtins.str"
      reveal_type("asd" + f)         # N: Revealed type is "Any | builtins.str"

      reveal_type(s + "bar")         # N: Revealed type is "builtins.str"
      reveal_type("foo" + s)         # N: Revealed type is "Any"
      reveal_type(s % "asd")         # N: Revealed type is "builtins.str"

      def foo(content: str) -> None:
        ...

      def bar(content: Promise) -> None:
        ...

      foo(s)                         # E: Argument 1 to "foo" has incompatible type "_StrPromise"; expected "str"  [arg-type]
      bar(s)

-   case: classproperty_usage
    main: |
      from typing import Any
      from django.utils.functional import classproperty
      from typing_extensions import reveal_type

      class Foo:
          @classproperty
          def attr(cls: Any) -> str: ...

          reveal_type(attr)      # N: Revealed type is "django.utils.functional.classproperty[builtins.str]"
          reveal_type(attr.getter)  # N: Revealed type is "def (method: def (Any) -> builtins.str) -> django.utils.functional.classproperty[builtins.str]"

      reveal_type(Foo.attr)      # N: Revealed type is "builtins.str"

      class Bar(Foo):
          def method(self) -> None:
              reveal_type(self.attr)  # N: Revealed type is "builtins.str"