Coverage for tests/fixtures/parsing/attributes.py: 54.73%
138 statements
« prev ^ index » next coverage.py v7.6.12, created at 2025-03-09 17:28 +0100
« prev ^ index » next coverage.py v7.6.12, created at 2025-03-09 17:28 +0100
1"""
2Module docstring.
4Attributes:
5 DESCRIBED_IN_MODULE_DOCSTRING: Described in module docstring.
6 DESCRIBED_AND_ANNOTATED_IN_MODULE_DOCSTRING (bool): Described and annotated in module docstring.
7 DESCRIBED_IN_BOTH: Described in both.
8 DESCRIBED_AND_ANNOTATED_IN_BOTH (bool): Described and annotated in both.
9"""
11from datetime import datetime
12from typing import Optional, Tuple
14from marshmallow import Schema, fields
15from pydantic import BaseModel
17NO_DOC_NO_TYPE = 0
19NO_TYPE = 1
20"""No type."""
22NO_DOC_NO_VALUE: int
24NO_VALUE: str
25"""No value."""
27NO_DOC: int = 2
29FULL: int = 3
30"""Full."""
32DESCRIBED_IN_MODULE_DOCSTRING: bool = True
33DESCRIBED_AND_ANNOTATED_IN_MODULE_DOCSTRING = True
35DESCRIBED_IN_BOTH: bool = True
36"""Described in both."""
38DESCRIBED_AND_ANNOTATED_IN_BOTH: bool = True
39"""Described and annotated in both."""
41COMPLEX_TYPE: Optional[Tuple[int, str]] = None
42"""Complex type."""
45ATTRIBUTE_C1: "C"
46"""Forward reference for type."""
49ATTRIBUTE_C2: Optional["C"] = None
50"""Optional forward reference for type."""
53class C:
54 """
55 Class doctring.
57 Attributes:
58 DESCRIBED_IN_CLASS_DOCSTRING: Described in class docstring.
59 DESCRIBED_AND_ANNOTATED_IN_CLASS_DOCSTRING (bool): Described and annotated in class docstring.
60 DESCRIBED_IN_BOTH: Described in both.
61 DESCRIBED_AND_ANNOTATED_IN_BOTH (bool): Described and annotated in both.
63 described_in_class_docstring: Described in class docstring.
64 described_and_annotated_in_class_docstring (bool): Described and annotated in class docstring.
65 described_in_both: Described in both.
66 described_and_annotated_in_both (bool): Described and annotated in both.
67 """
69 IN_CLASS = 0
70 """In class."""
72 DESCRIBED_IN_CLASS_DOCSTRING: bool = True
73 DESCRIBED_AND_ANNOTATED_IN_CLASS_DOCSTRING = True
75 DESCRIBED_IN_BOTH: bool = True
76 """Described in both."""
78 DESCRIBED_AND_ANNOTATED_IN_BOTH: bool = True
79 """Described and annotated in both."""
81 both_class_and_instance_attribute: Optional[bool] = None
83 def __init__(self) -> None:
84 self.in_init = True
85 """In init."""
87 self.annotated_in_init: bool = True
88 """Annotated in init."""
90 self.described_in_class_docstring: bool = True
91 self.described_and_annotated_in_class_docstring = True
93 self.described_in_both: bool = True
94 """Described in both."""
96 self.described_and_annotated_in_both: bool = True
97 """Described and annotated in both."""
99 non_attribute: bool = True
100 """Non attribute."""
102 if not self.both_class_and_instance_attribute:
103 self.both_class_and_instance_attribute = True
106class D:
107 def __init__(self) -> None:
108 """
109 Init doctring.
111 Attributes:
112 described_in_class_docstring: Described in class docstring.
113 described_and_annotated_in_class_docstring (bool): Described and annotated in class docstring.
114 described_in_both: Described in both.
115 described_and_annotated_in_both (bool): Described and annotated in both.
116 """
117 self.in_init = True
118 """In init."""
120 self.annotated_in_init: bool = True
121 """Annotated in init."""
123 self.described_in_class_docstring: bool = True
124 self.described_and_annotated_in_class_docstring = True
126 self.described_in_both: bool = True
127 """Described in both."""
129 self.described_and_annotated_in_both: bool = True
130 """Described and annotated in both."""
132 non_attribute: bool = True
133 """Non attribute."""
135 if not self.both_class_and_instance_attribute: # type: ignore[has-type]
136 self.both_class_and_instance_attribute = True
139class E:
140 """
141 Class doctring.
143 Attributes:
144 DESCRIBED_IN_CLASS_DOCSTRING: Described in class docstring.
145 DESCRIBED_AND_ANNOTATED_IN_CLASS_DOCSTRING (bool): Described and annotated in class docstring.
146 DESCRIBED_IN_BOTH: Described in both.
147 DESCRIBED_AND_ANNOTATED_IN_BOTH (bool): Described and annotated in both.
149 described_in_class_and_init_docstring: Described in class and init docstring.
150 described_and_annotated_in_class_and_init_docstring (bool): Described and annotated in class and init docstring.
151 described_everywhere: Described everywhere.
152 described_and_annotated_everywhere (bool): Described and annotated everywhere.
153 """
155 IN_CLASS = 0
156 """In class."""
158 DESCRIBED_IN_CLASS_DOCSTRING: bool = True
159 DESCRIBED_AND_ANNOTATED_IN_CLASS_DOCSTRING = True
161 DESCRIBED_IN_BOTH: bool = True
162 """Described in both."""
164 DESCRIBED_AND_ANNOTATED_IN_BOTH: bool = True
165 """Described and annotated in both."""
167 both_class_and_instance_attribute: Optional[bool] = None
169 DEDENT = 0
170 """This docstring starts immediately (no blank line).
171 Use `inspect.cleandoc` instead of `textwrap.dedent`."""
173 def __init__(self) -> None:
174 """
175 Init doctring.
177 Attributes:
178 described_in_class_and_init_docstring: Described in class and init docstring.
179 described_and_annotated_in_class_and_init_docstring (bool): Described and annotated in class and init docstring.
180 described_everywhere: Described everywhere.
181 described_and_annotated_everywhere (bool): Described and annotated everywhere.
182 """
183 self.in_init = True
184 """In init."""
186 self.annotated_in_init: bool = True
187 """Annotated in init."""
189 self.described_in_class_and_init_docstring: bool = True
190 self.described_and_annotated_in_class_and_init_docstring = True
192 self.described_everywhere: bool = True
193 """Described everywhere."""
195 self.described_and_annotated_everywhere: bool = True
196 """Described and annotated everywhere."""
198 non_attribute: bool = True
199 """Non attribute."""
201 non_attribute2 = True
202 """Non attribute 2."""
204 if not self.both_class_and_instance_attribute:
205 self.both_class_and_instance_attribute = True
207 d = D()
208 d.non_self_attribute = 0 # type: ignore[attr-defined]
209 """Non self attribute."""
211 self.d = d
212 self.d.non_self_attribute2 = 0 # type: ignore[attr-defined]
213 """Non self attribute 2."""
215 c = C()
216 c.non_self_attribute: int = 0 # type: ignore[attr-defined,misc]
217 """Non self attribute."""
219 self.c = c
220 self.c.non_self_attribute2: int = 0 # type: ignore[attr-defined,misc]
221 """Non self attribute 2."""
223 self.dedent = 0
224 """This docstring starts immediately (no blank line).
225 Use `inspect.cleandoc` instead of `textwrap.dedent`."""
228if True:
229 IN_IF: bytes = b""
230 """In if."""
232 ANNOTATED_IN_IF: str = ""
233 """Annotated in if."""
234else:
235 IN_ELSE: list = []
236 """In else."""
238try:
239 IN_TRY: int = 1000
240 """In try."""
241except: # noqa
242 IN_EXCEPT: float = 9000.0
243 """In except."""
244else:
245 IN_TRY_ELSE: str = "-1"
246 """In try else."""
247finally:
248 IN_FINALLY: bool = bool(-9000)
249 """In finally."""
252class Model(BaseModel):
253 in_pydantic_model: int
254 """In Pydantic model."""
256 model_field: Optional[datetime] = None
257 """A model field."""
260class MarshmallowSchema(Schema):
261 in_marshmallow_model: int
262 """In Marshmallow model."""
264 model_field: fields.Str = fields.Str()
265 """A model field."""
268OK, WARNING, CRITICAL, UNKNOWN = 0, 0, 0, 0
270if True:
271 DEDENT = 0
272 """This docstring starts immediately (no blank line).
273 Use `inspect.cleandoc` instead of `textwrap.dedent`."""