@@ -438,7 +438,7 @@ class Module(LocalsDictNodeNG):
438
438
def __init__ (
439
439
self ,
440
440
name : str ,
441
- doc : Optional [str ],
441
+ doc : Optional [str ] = None ,
442
442
file : Optional [str ] = None ,
443
443
path : Optional [List [str ]] = None ,
444
444
package : Optional [bool ] = None ,
@@ -463,7 +463,7 @@ def __init__(
463
463
self .name = name
464
464
"""The name of the module."""
465
465
466
- self .doc = doc
466
+ self ._doc = doc
467
467
"""The module docstring."""
468
468
469
469
self .file = file
@@ -509,6 +509,27 @@ def postinit(self, body=None, *, doc_node: Optional[Const] = None):
509
509
"""
510
510
self .body = body
511
511
self .doc_node = doc_node
512
+ if doc_node :
513
+ self ._doc = doc_node .value
514
+
515
+ @property
516
+ def doc (self ) -> Optional [str ]:
517
+ """The module docstring."""
518
+ warnings .warn (
519
+ "The 'Module.doc' attribute is deprecated, "
520
+ "use 'Module.doc_node' instead." ,
521
+ DeprecationWarning ,
522
+ )
523
+ return self ._doc
524
+
525
+ @doc .setter
526
+ def doc (self , value : Optional [str ]) -> None :
527
+ warnings .warn (
528
+ "Setting the 'Module.doc' attribute is deprecated, "
529
+ "use 'Module.doc_node' instead." ,
530
+ DeprecationWarning ,
531
+ )
532
+ self ._doc = value
512
533
513
534
def _get_stream (self ):
514
535
if self .file_bytes is not None :
@@ -1515,7 +1536,7 @@ class FunctionDef(mixins.MultiLineBlockMixin, node_classes.Statement, Lambda):
1515
1536
def __init__ (
1516
1537
self ,
1517
1538
name = None ,
1518
- doc = None ,
1539
+ doc : Optional [ str ] = None ,
1519
1540
lineno = None ,
1520
1541
col_offset = None ,
1521
1542
parent = None ,
@@ -1527,8 +1548,7 @@ def __init__(
1527
1548
:param name: The name of the function.
1528
1549
:type name: str or None
1529
1550
1530
- :param doc: The function's docstring.
1531
- :type doc: str or None
1551
+ :param doc: The function docstring.
1532
1552
1533
1553
:param lineno: The line that this node appears on in the source code.
1534
1554
:type lineno: int or None
@@ -1553,11 +1573,8 @@ def __init__(
1553
1573
:type name: str or None
1554
1574
"""
1555
1575
1556
- self .doc = doc
1557
- """The function's docstring.
1558
-
1559
- :type doc: str or None
1560
- """
1576
+ self ._doc = doc
1577
+ """The function docstring."""
1561
1578
1562
1579
self .doc_node : Optional [Const ] = None
1563
1580
"""The doc node associated with this node."""
@@ -1614,6 +1631,27 @@ def postinit(
1614
1631
self .type_comment_args = type_comment_args
1615
1632
self .position = position
1616
1633
self .doc_node = doc_node
1634
+ if doc_node :
1635
+ self ._doc = doc_node .value
1636
+
1637
+ @property
1638
+ def doc (self ) -> Optional [str ]:
1639
+ """The function docstring."""
1640
+ warnings .warn (
1641
+ "The 'FunctionDef.doc' attribute is deprecated, "
1642
+ "use 'FunctionDef.doc_node' instead." ,
1643
+ DeprecationWarning ,
1644
+ )
1645
+ return self ._doc
1646
+
1647
+ @doc .setter
1648
+ def doc (self , value : Optional [str ]) -> None :
1649
+ warnings .warn (
1650
+ "Setting the 'FunctionDef.doc' attribute is deprecated, "
1651
+ "use 'FunctionDef.doc_node' instead." ,
1652
+ DeprecationWarning ,
1653
+ )
1654
+ self ._doc = value
1617
1655
1618
1656
@cached_property
1619
1657
def extra_decorators (self ) -> List [node_classes .Call ]:
@@ -2164,7 +2202,7 @@ def my_meth(self, arg):
2164
2202
def __init__ (
2165
2203
self ,
2166
2204
name = None ,
2167
- doc = None ,
2205
+ doc : Optional [ str ] = None ,
2168
2206
lineno = None ,
2169
2207
col_offset = None ,
2170
2208
parent = None ,
@@ -2176,8 +2214,7 @@ def __init__(
2176
2214
:param name: The name of the class.
2177
2215
:type name: str or None
2178
2216
2179
- :param doc: The function's docstring.
2180
- :type doc: str or None
2217
+ :param doc: The class docstring.
2181
2218
2182
2219
:param lineno: The line that this node appears on in the source code.
2183
2220
:type lineno: int or None
@@ -2229,11 +2266,8 @@ def __init__(
2229
2266
:type name: str or None
2230
2267
"""
2231
2268
2232
- self .doc = doc
2233
- """The class' docstring.
2234
-
2235
- :type doc: str or None
2236
- """
2269
+ self ._doc = doc
2270
+ """The class docstring."""
2237
2271
2238
2272
self .doc_node : Optional [Const ] = None
2239
2273
"""The doc node associated with this node."""
@@ -2254,6 +2288,25 @@ def __init__(
2254
2288
for local_name , node in self .implicit_locals ():
2255
2289
self .add_local_node (node , local_name )
2256
2290
2291
+ @property
2292
+ def doc (self ) -> Optional [str ]:
2293
+ """The class docstring."""
2294
+ warnings .warn (
2295
+ "The 'ClassDef.doc' attribute is deprecated, "
2296
+ "use 'ClassDef.doc_node' instead." ,
2297
+ DeprecationWarning ,
2298
+ )
2299
+ return self ._doc
2300
+
2301
+ @doc .setter
2302
+ def doc (self , value : Optional [str ]) -> None :
2303
+ warnings .warn (
2304
+ "Setting the 'ClassDef.doc' attribute is deprecated, "
2305
+ "use 'ClassDef.doc_node.value' instead." ,
2306
+ DeprecationWarning ,
2307
+ )
2308
+ self ._doc = value
2309
+
2257
2310
def implicit_parameters (self ):
2258
2311
return 1
2259
2312
@@ -2316,6 +2369,8 @@ def postinit(
2316
2369
self ._metaclass = metaclass
2317
2370
self .position = position
2318
2371
self .doc_node = doc_node
2372
+ if doc_node :
2373
+ self ._doc = doc_node .value
2319
2374
2320
2375
def _newstyle_impl (self , context = None ):
2321
2376
if context is None :
0 commit comments