10
10
from pydoclint .utils .edge_case_error import EdgeCaseError
11
11
from pydoclint .utils .generic import (
12
12
appendArgsToCheckToV105 ,
13
+ buildClassAttrToDefaultMapping ,
13
14
getDocstring ,
14
15
specialEqual ,
15
16
stripQuotes ,
@@ -42,6 +43,7 @@ def checkClassAttributesAgainstClassDocstring(
42
43
shouldDocumentPrivateClassAttributes : bool ,
43
44
treatPropertyMethodsAsClassAttributes : bool ,
44
45
onlyAttrsWithClassVarAreTreatedAsClassAttrs : bool ,
46
+ checkArgDefaults : bool ,
45
47
) -> None :
46
48
"""Check class attribute list against the attribute list in docstring"""
47
49
actualArgs : ArgList = extractClassAttributesFromNode (
@@ -53,6 +55,7 @@ def checkClassAttributesAgainstClassDocstring(
53
55
onlyAttrsWithClassVarAreTreatedAsClassAttrs = (
54
56
onlyAttrsWithClassVarAreTreatedAsClassAttrs
55
57
),
58
+ checkArgDefaults = checkArgDefaults ,
56
59
)
57
60
58
61
classDocstring : str = getDocstring (node )
@@ -126,12 +129,13 @@ def checkClassAttributesAgainstClassDocstring(
126
129
)
127
130
128
131
129
- def extractClassAttributesFromNode (
132
+ def extractClassAttributesFromNode ( # noqa: C901
130
133
* ,
131
134
node : ast .ClassDef ,
132
135
shouldDocumentPrivateClassAttributes : bool ,
133
136
treatPropertyMethodsAsClassAttrs : bool ,
134
137
onlyAttrsWithClassVarAreTreatedAsClassAttrs : bool ,
138
+ checkArgDefaults : bool ,
135
139
) -> ArgList :
136
140
"""
137
141
Extract class attributes from an AST node.
@@ -151,6 +155,9 @@ def extractClassAttributesFromNode(
151
155
within ``ClassVar`` (where ``ClassVar`` is imported from ``typing``)
152
156
are treated as class attributes, and all other attributes are
153
157
treated as instance attributes.
158
+ checkArgDefaults : bool
159
+ If True, we should extract the arguments' default values and attach
160
+ them to the type hints.
154
161
155
162
Returns
156
163
-------
@@ -201,7 +208,21 @@ def extractClassAttributesFromNode(
201
208
)
202
209
]
203
210
204
- return ArgList (infoList = atl )
211
+ astArgList = ArgList (infoList = atl )
212
+
213
+ if not checkArgDefaults : # no need to add defaults to type hints
214
+ return astArgList
215
+
216
+ argToDefaultMapping : dict [str , ast .expr ] = buildClassAttrToDefaultMapping (
217
+ node ,
218
+ )
219
+
220
+ return ArgList (
221
+ [
222
+ Arg .fromArgWithMapping (_ , argToDefaultMapping )
223
+ for _ in astArgList .infoList
224
+ ]
225
+ )
205
226
206
227
207
228
def checkDocArgsLengthAgainstActualArgs (
0 commit comments