@@ -438,7 +438,7 @@ class Module(LocalsDictNodeNG):
438438 def __init__ (
439439 self ,
440440 name : str ,
441- doc : Optional [str ],
441+ doc : Optional [str ] = None ,
442442 file : Optional [str ] = None ,
443443 path : Optional [List [str ]] = None ,
444444 package : Optional [bool ] = None ,
@@ -463,7 +463,7 @@ def __init__(
463463 self .name = name
464464 """The name of the module."""
465465
466- self .doc = doc
466+ self ._doc = doc
467467 """The module docstring."""
468468
469469 self .file = file
@@ -509,6 +509,27 @@ def postinit(self, body=None, *, doc_node: Optional[Const] = None):
509509 """
510510 self .body = body
511511 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
512533
513534 def _get_stream (self ):
514535 if self .file_bytes is not None :
@@ -1515,7 +1536,7 @@ class FunctionDef(mixins.MultiLineBlockMixin, node_classes.Statement, Lambda):
15151536 def __init__ (
15161537 self ,
15171538 name = None ,
1518- doc = None ,
1539+ doc : Optional [ str ] = None ,
15191540 lineno = None ,
15201541 col_offset = None ,
15211542 parent = None ,
@@ -1527,8 +1548,7 @@ def __init__(
15271548 :param name: The name of the function.
15281549 :type name: str or None
15291550
1530- :param doc: The function's docstring.
1531- :type doc: str or None
1551+ :param doc: The function docstring.
15321552
15331553 :param lineno: The line that this node appears on in the source code.
15341554 :type lineno: int or None
@@ -1553,11 +1573,8 @@ def __init__(
15531573 :type name: str or None
15541574 """
15551575
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."""
15611578
15621579 self .doc_node : Optional [Const ] = None
15631580 """The doc node associated with this node."""
@@ -1614,6 +1631,27 @@ def postinit(
16141631 self .type_comment_args = type_comment_args
16151632 self .position = position
16161633 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
16171655
16181656 @cached_property
16191657 def extra_decorators (self ) -> List [node_classes .Call ]:
@@ -2164,7 +2202,7 @@ def my_meth(self, arg):
21642202 def __init__ (
21652203 self ,
21662204 name = None ,
2167- doc = None ,
2205+ doc : Optional [ str ] = None ,
21682206 lineno = None ,
21692207 col_offset = None ,
21702208 parent = None ,
@@ -2176,8 +2214,7 @@ def __init__(
21762214 :param name: The name of the class.
21772215 :type name: str or None
21782216
2179- :param doc: The function's docstring.
2180- :type doc: str or None
2217+ :param doc: The class docstring.
21812218
21822219 :param lineno: The line that this node appears on in the source code.
21832220 :type lineno: int or None
@@ -2229,11 +2266,8 @@ def __init__(
22292266 :type name: str or None
22302267 """
22312268
2232- self .doc = doc
2233- """The class' docstring.
2234-
2235- :type doc: str or None
2236- """
2269+ self ._doc = doc
2270+ """The class docstring."""
22372271
22382272 self .doc_node : Optional [Const ] = None
22392273 """The doc node associated with this node."""
@@ -2254,6 +2288,25 @@ def __init__(
22542288 for local_name , node in self .implicit_locals ():
22552289 self .add_local_node (node , local_name )
22562290
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+
22572310 def implicit_parameters (self ):
22582311 return 1
22592312
@@ -2316,6 +2369,8 @@ def postinit(
23162369 self ._metaclass = metaclass
23172370 self .position = position
23182371 self .doc_node = doc_node
2372+ if doc_node :
2373+ self ._doc = doc_node .value
23192374
23202375 def _newstyle_impl (self , context = None ):
23212376 if context is None :
0 commit comments