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

1""" 

2Module docstring. 

3 

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""" 

10 

11from datetime import datetime 

12from typing import Optional, Tuple 

13 

14from marshmallow import Schema, fields 

15from pydantic import BaseModel 

16 

17NO_DOC_NO_TYPE = 0 

18 

19NO_TYPE = 1 

20"""No type.""" 

21 

22NO_DOC_NO_VALUE: int 

23 

24NO_VALUE: str 

25"""No value.""" 

26 

27NO_DOC: int = 2 

28 

29FULL: int = 3 

30"""Full.""" 

31 

32DESCRIBED_IN_MODULE_DOCSTRING: bool = True 

33DESCRIBED_AND_ANNOTATED_IN_MODULE_DOCSTRING = True 

34 

35DESCRIBED_IN_BOTH: bool = True 

36"""Described in both.""" 

37 

38DESCRIBED_AND_ANNOTATED_IN_BOTH: bool = True 

39"""Described and annotated in both.""" 

40 

41COMPLEX_TYPE: Optional[Tuple[int, str]] = None 

42"""Complex type.""" 

43 

44 

45ATTRIBUTE_C1: "C" 

46"""Forward reference for type.""" 

47 

48 

49ATTRIBUTE_C2: Optional["C"] = None 

50"""Optional forward reference for type.""" 

51 

52 

53class C: 

54 """ 

55 Class doctring. 

56 

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. 

62 

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 """ 

68 

69 IN_CLASS = 0 

70 """In class.""" 

71 

72 DESCRIBED_IN_CLASS_DOCSTRING: bool = True 

73 DESCRIBED_AND_ANNOTATED_IN_CLASS_DOCSTRING = True 

74 

75 DESCRIBED_IN_BOTH: bool = True 

76 """Described in both.""" 

77 

78 DESCRIBED_AND_ANNOTATED_IN_BOTH: bool = True 

79 """Described and annotated in both.""" 

80 

81 both_class_and_instance_attribute: Optional[bool] = None 

82 

83 def __init__(self) -> None: 

84 self.in_init = True 

85 """In init.""" 

86 

87 self.annotated_in_init: bool = True 

88 """Annotated in init.""" 

89 

90 self.described_in_class_docstring: bool = True 

91 self.described_and_annotated_in_class_docstring = True 

92 

93 self.described_in_both: bool = True 

94 """Described in both.""" 

95 

96 self.described_and_annotated_in_both: bool = True 

97 """Described and annotated in both.""" 

98 

99 non_attribute: bool = True 

100 """Non attribute.""" 

101 

102 if not self.both_class_and_instance_attribute: 

103 self.both_class_and_instance_attribute = True 

104 

105 

106class D: 

107 def __init__(self) -> None: 

108 """ 

109 Init doctring. 

110 

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.""" 

119 

120 self.annotated_in_init: bool = True 

121 """Annotated in init.""" 

122 

123 self.described_in_class_docstring: bool = True 

124 self.described_and_annotated_in_class_docstring = True 

125 

126 self.described_in_both: bool = True 

127 """Described in both.""" 

128 

129 self.described_and_annotated_in_both: bool = True 

130 """Described and annotated in both.""" 

131 

132 non_attribute: bool = True 

133 """Non attribute.""" 

134 

135 if not self.both_class_and_instance_attribute: # type: ignore[has-type] 

136 self.both_class_and_instance_attribute = True 

137 

138 

139class E: 

140 """ 

141 Class doctring. 

142 

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. 

148 

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 """ 

154 

155 IN_CLASS = 0 

156 """In class.""" 

157 

158 DESCRIBED_IN_CLASS_DOCSTRING: bool = True 

159 DESCRIBED_AND_ANNOTATED_IN_CLASS_DOCSTRING = True 

160 

161 DESCRIBED_IN_BOTH: bool = True 

162 """Described in both.""" 

163 

164 DESCRIBED_AND_ANNOTATED_IN_BOTH: bool = True 

165 """Described and annotated in both.""" 

166 

167 both_class_and_instance_attribute: Optional[bool] = None 

168 

169 DEDENT = 0 

170 """This docstring starts immediately (no blank line). 

171 Use `inspect.cleandoc` instead of `textwrap.dedent`.""" 

172 

173 def __init__(self) -> None: 

174 """ 

175 Init doctring. 

176 

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.""" 

185 

186 self.annotated_in_init: bool = True 

187 """Annotated in init.""" 

188 

189 self.described_in_class_and_init_docstring: bool = True 

190 self.described_and_annotated_in_class_and_init_docstring = True 

191 

192 self.described_everywhere: bool = True 

193 """Described everywhere.""" 

194 

195 self.described_and_annotated_everywhere: bool = True 

196 """Described and annotated everywhere.""" 

197 

198 non_attribute: bool = True 

199 """Non attribute.""" 

200 

201 non_attribute2 = True 

202 """Non attribute 2.""" 

203 

204 if not self.both_class_and_instance_attribute: 

205 self.both_class_and_instance_attribute = True 

206 

207 d = D() 

208 d.non_self_attribute = 0 # type: ignore[attr-defined] 

209 """Non self attribute.""" 

210 

211 self.d = d 

212 self.d.non_self_attribute2 = 0 # type: ignore[attr-defined] 

213 """Non self attribute 2.""" 

214 

215 c = C() 

216 c.non_self_attribute: int = 0 # type: ignore[attr-defined,misc] 

217 """Non self attribute.""" 

218 

219 self.c = c 

220 self.c.non_self_attribute2: int = 0 # type: ignore[attr-defined,misc] 

221 """Non self attribute 2.""" 

222 

223 self.dedent = 0 

224 """This docstring starts immediately (no blank line). 

225 Use `inspect.cleandoc` instead of `textwrap.dedent`.""" 

226 

227 

228if True: 

229 IN_IF: bytes = b"" 

230 """In if.""" 

231 

232 ANNOTATED_IN_IF: str = "" 

233 """Annotated in if.""" 

234else: 

235 IN_ELSE: list = [] 

236 """In else.""" 

237 

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.""" 

250 

251 

252class Model(BaseModel): 

253 in_pydantic_model: int 

254 """In Pydantic model.""" 

255 

256 model_field: Optional[datetime] = None 

257 """A model field.""" 

258 

259 

260class MarshmallowSchema(Schema): 

261 in_marshmallow_model: int 

262 """In Marshmallow model.""" 

263 

264 model_field: fields.Str = fields.Str() 

265 """A model field.""" 

266 

267 

268OK, WARNING, CRITICAL, UNKNOWN = 0, 0, 0, 0 

269 

270if True: 

271 DEDENT = 0 

272 """This docstring starts immediately (no blank line). 

273 Use `inspect.cleandoc` instead of `textwrap.dedent`."""