Skip to content

Commit 310b62a

Browse files
authored
Remove deprecated doc attribute (#2154)
1 parent 08ed413 commit 310b62a

File tree

8 files changed

+9
-206
lines changed

8 files changed

+9
-206
lines changed

ChangeLog

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,18 @@ Release date: TBA
121121

122122
Refs #2141
123123

124+
* Remove deprecated ``Ellipsis``, ``ExtSlice``, ``Index`` nodes.
125+
126+
Refs #2152
127+
124128
* Remove deprecated ``is_sys_guard`` and ``is_typing_guard`` methods.
125129

126130
Refs #2153
127131

128-
* Remove deprecated ``Ellipsis``, ``ExtSlice``, ``Index`` nodes.
132+
* Remove deprecated ``doc`` attribute for ``Module``, ``ClassDef``, and ``FunctionDef``.
133+
Use the ``doc_node`` attribute instead.
129134

130-
Refs #2152
135+
Refs #2154
131136

132137

133138
What's New in astroid 2.15.5?

astroid/nodes/scoped_nodes/scoped_nodes.py

Lines changed: 2 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,6 @@ class Module(LocalsDictNodeNG):
201201

202202
_other_fields = (
203203
"name",
204-
"doc",
205204
"file",
206205
"path",
207206
"package",
@@ -221,9 +220,6 @@ def __init__(
221220
self.name = name
222221
"""The name of the module."""
223222

224-
self._doc: str | None = None
225-
"""The module docstring."""
226-
227223
self.file = file
228224
"""The path to the file that this ast has been extracted from.
229225
@@ -262,29 +258,6 @@ def postinit(
262258
):
263259
self.body = body
264260
self.doc_node = doc_node
265-
if doc_node:
266-
self._doc = doc_node.value
267-
268-
@property
269-
def doc(self) -> str | None:
270-
"""The module docstring."""
271-
warnings.warn(
272-
"The 'Module.doc' attribute is deprecated, "
273-
"use 'Module.doc_node' instead.",
274-
DeprecationWarning,
275-
stacklevel=2,
276-
)
277-
return self._doc
278-
279-
@doc.setter
280-
def doc(self, value: str | None) -> None:
281-
warnings.warn(
282-
"Setting the 'Module.doc' attribute is deprecated, "
283-
"use 'Module.doc_node' instead.",
284-
DeprecationWarning,
285-
stacklevel=2,
286-
)
287-
self._doc = value
288261

289262
def _get_stream(self):
290263
if self.file_bytes is not None:
@@ -1115,7 +1088,7 @@ class FunctionDef(
11151088
type_comment_returns = None
11161089
"""If present, this will contain the return type annotation, passed by a type comment"""
11171090
# attributes below are set by the builder module or by raw factories
1118-
_other_fields = ("name", "doc", "position")
1091+
_other_fields = ("name", "position")
11191092
_other_other_fields = (
11201093
"locals",
11211094
"_type",
@@ -1144,9 +1117,6 @@ def __init__(
11441117
self.name = name
11451118
"""The name of the function."""
11461119

1147-
self._doc: str | None = None
1148-
"""DEPRECATED: The function docstring."""
1149-
11501120
self.locals = {}
11511121
"""A map of the name of a local variable to the node defining it."""
11521122

@@ -1203,29 +1173,6 @@ def postinit(
12031173
self.type_comment_args = type_comment_args
12041174
self.position = position
12051175
self.doc_node = doc_node
1206-
if doc_node:
1207-
self._doc = doc_node.value
1208-
1209-
@property
1210-
def doc(self) -> str | None:
1211-
"""The function docstring."""
1212-
warnings.warn(
1213-
"The 'FunctionDef.doc' attribute is deprecated, "
1214-
"use 'FunctionDef.doc_node' instead.",
1215-
DeprecationWarning,
1216-
stacklevel=2,
1217-
)
1218-
return self._doc
1219-
1220-
@doc.setter
1221-
def doc(self, value: str | None) -> None:
1222-
warnings.warn(
1223-
"Setting the 'FunctionDef.doc' attribute is deprecated, "
1224-
"use 'FunctionDef.doc_node' instead.",
1225-
DeprecationWarning,
1226-
stacklevel=2,
1227-
)
1228-
self._doc = value
12291176

12301177
@cached_property
12311178
def extra_decorators(self) -> list[node_classes.Call]:
@@ -1850,7 +1797,7 @@ def my_meth(self, arg):
18501797
":type: str"
18511798
),
18521799
)
1853-
_other_fields = ("name", "doc", "is_dataclass", "position")
1800+
_other_fields = ("name", "is_dataclass", "position")
18541801
_other_other_fields = ("locals", "_newstyle")
18551802
_newstyle: bool | None = None
18561803

@@ -1886,9 +1833,6 @@ def __init__(
18861833
self.decorators = None
18871834
"""The decorators that are applied to this class."""
18881835

1889-
self._doc: str | None = None
1890-
"""DEPRECATED: The class docstring."""
1891-
18921836
self.doc_node: Const | None = None
18931837
"""The doc node associated with this node."""
18941838

@@ -1910,27 +1854,6 @@ def __init__(
19101854

19111855
infer_binary_op: ClassVar[InferBinaryOp[ClassDef]]
19121856

1913-
@property
1914-
def doc(self) -> str | None:
1915-
"""The class docstring."""
1916-
warnings.warn(
1917-
"The 'ClassDef.doc' attribute is deprecated, "
1918-
"use 'ClassDef.doc_node' instead.",
1919-
DeprecationWarning,
1920-
stacklevel=2,
1921-
)
1922-
return self._doc
1923-
1924-
@doc.setter
1925-
def doc(self, value: str | None) -> None:
1926-
warnings.warn(
1927-
"Setting the 'ClassDef.doc' attribute is deprecated, "
1928-
"use 'ClassDef.doc_node.value' instead.",
1929-
DeprecationWarning,
1930-
stacklevel=2,
1931-
)
1932-
self._doc = value
1933-
19341857
def implicit_parameters(self) -> Literal[1]:
19351858
return 1
19361859

@@ -1967,8 +1890,6 @@ def postinit(
19671890
self._metaclass = metaclass
19681891
self.position = position
19691892
self.doc_node = doc_node
1970-
if doc_node:
1971-
self._doc = doc_node.value
19721893

19731894
def _newstyle_impl(self, context: InferenceContext | None = None):
19741895
if context is None:

tests/brain/test_brain.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1777,9 +1777,6 @@ def test(a, b):
17771777
assert isinstance(partial, objects.PartialFunction)
17781778
assert isinstance(partial.doc_node, nodes.Const)
17791779
assert partial.doc_node.value == "Docstring"
1780-
with pytest.warns(DeprecationWarning) as records:
1781-
assert partial.doc == "Docstring"
1782-
assert len(records) == 1
17831780
assert partial.lineno == 3
17841781
assert partial.col_offset == 0
17851782

tests/test_builder.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -751,9 +751,6 @@ def test_module_base_props(self) -> None:
751751
"""Test base properties and method of an astroid module."""
752752
module = self.module
753753
self.assertEqual(module.name, "data.module")
754-
with pytest.warns(DeprecationWarning) as records:
755-
self.assertEqual(module.doc, "test module for astroid\n")
756-
assert len(records) == 1
757754
assert isinstance(module.doc_node, nodes.Const)
758755
self.assertEqual(module.doc_node.value, "test module for astroid\n")
759756
self.assertEqual(module.fromlineno, 0)
@@ -797,9 +794,6 @@ def test_function_base_props(self) -> None:
797794
module = self.module
798795
function = module["global_access"]
799796
self.assertEqual(function.name, "global_access")
800-
with pytest.warns(DeprecationWarning) as records:
801-
self.assertEqual(function.doc, "function test")
802-
assert len(records)
803797
assert isinstance(function.doc_node, nodes.Const)
804798
self.assertEqual(function.doc_node.value, "function test")
805799
self.assertEqual(function.fromlineno, 11)
@@ -824,9 +818,6 @@ def test_class_base_props(self) -> None:
824818
module = self.module
825819
klass = module["YO"]
826820
self.assertEqual(klass.name, "YO")
827-
with pytest.warns(DeprecationWarning) as records:
828-
self.assertEqual(klass.doc, "hehe\n haha")
829-
assert len(records) == 1
830821
assert isinstance(klass.doc_node, nodes.Const)
831822
self.assertEqual(klass.doc_node.value, "hehe\n haha")
832823
self.assertEqual(klass.fromlineno, 25)
@@ -882,9 +873,6 @@ def test_method_base_props(self) -> None:
882873
method = klass2["method"]
883874
self.assertEqual(method.name, "method")
884875
self.assertEqual([n.name for n in method.args.args], ["self"])
885-
with pytest.warns(DeprecationWarning) as records:
886-
self.assertEqual(method.doc, "method\n test")
887-
assert len(records) == 1
888876
assert isinstance(method.doc_node, nodes.Const)
889877
self.assertEqual(method.doc_node.value, "method\n test")
890878
self.assertEqual(method.fromlineno, 48)

tests/test_inference.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6440,9 +6440,6 @@ def test(self):
64406440
assert isinstance(inferred, objects.Property)
64416441
assert isinstance(inferred.doc_node, nodes.Const)
64426442
assert inferred.doc_node.value == "Docstring"
6443-
with pytest.warns(DeprecationWarning) as records:
6444-
assert inferred.doc == "Docstring"
6445-
assert len(records) == 1
64466443

64476444

64486445
def test_recursion_error_inferring_builtin_containers() -> None:

tests/test_nodes.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1535,9 +1535,6 @@ def func():
15351535
"""
15361536
)
15371537
node: nodes.FunctionDef = astroid.extract_node(code) # type: ignore[assignment]
1538-
with pytest.warns(DeprecationWarning) as records:
1539-
assert node.doc == "Docstring"
1540-
assert len(records) == 1
15411538
assert isinstance(node.doc_node, nodes.Const)
15421539
assert node.doc_node.value == "Docstring"
15431540
assert node.doc_node.lineno == 2
@@ -1553,9 +1550,6 @@ def func():
15531550
"""
15541551
)
15551552
node = astroid.extract_node(code)
1556-
with pytest.warns(DeprecationWarning) as records:
1557-
assert node.doc is None
1558-
assert len(records) == 1
15591553
assert node.doc_node is None
15601554

15611555

tests/test_raw_building.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,11 @@ def test_build_module(self) -> None:
5050
def test_build_class(self) -> None:
5151
node = build_class("MyClass")
5252
self.assertEqual(node.name, "MyClass")
53-
with pytest.warns(DeprecationWarning) as records:
54-
self.assertEqual(node.doc, None)
55-
assert len(records) == 1
5653
self.assertEqual(node.doc_node, None)
5754

5855
def test_build_function(self) -> None:
5956
node = build_function("MyFunction")
6057
self.assertEqual(node.name, "MyFunction")
61-
with pytest.warns(DeprecationWarning) as records:
62-
self.assertEqual(node.doc, None)
63-
assert len(records) == 1
6458
self.assertEqual(node.doc_node, None)
6559

6660
def test_build_function_args(self) -> None:

tests/test_scoped_nodes.py

Lines changed: 0 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import sys
1414
import textwrap
1515
import unittest
16-
import warnings
1716
from functools import partial
1817
from typing import Any
1918

@@ -991,9 +990,6 @@ def test_cls_special_attributes_1(self) -> None:
991990
self.assertEqual(
992991
len(cls.getattr("__doc__")), 1, (cls, cls.getattr("__doc__"))
993992
)
994-
with pytest.warns(DeprecationWarning) as records:
995-
self.assertEqual(cls.getattr("__doc__")[0].value, cls.doc)
996-
assert len(records) == 1
997993
self.assertEqual(cls.getattr("__doc__")[0].value, cls.doc_node.value)
998994
self.assertEqual(len(cls.getattr("__module__")), 4)
999995
self.assertEqual(len(cls.getattr("__dict__")), 1)
@@ -2849,92 +2845,3 @@ def test_non_frame_node():
28492845

28502846
assert module.body[1].value.locals["x"][0].frame() == module
28512847
assert module.body[1].value.locals["x"][0].frame(future=True) == module
2852-
2853-
2854-
def test_deprecation_of_doc_attribute() -> None:
2855-
code = textwrap.dedent(
2856-
"""\
2857-
def func():
2858-
"Docstring"
2859-
return 1
2860-
"""
2861-
)
2862-
node: nodes.FunctionDef = extract_node(code) # type: ignore[assignment]
2863-
with pytest.warns(DeprecationWarning) as records:
2864-
assert node.doc == "Docstring"
2865-
assert len(records) == 1
2866-
with pytest.warns(DeprecationWarning) as records:
2867-
node.doc = None
2868-
assert len(records) == 1
2869-
2870-
code = textwrap.dedent(
2871-
"""\
2872-
class MyClass():
2873-
'''Docstring'''
2874-
"""
2875-
)
2876-
node: nodes.ClassDef = extract_node(code) # type: ignore[assignment]
2877-
with pytest.warns(DeprecationWarning) as records:
2878-
assert node.doc == "Docstring"
2879-
assert len(records) == 1
2880-
with pytest.warns(DeprecationWarning) as records:
2881-
node.doc = None
2882-
assert len(records) == 1
2883-
2884-
code = textwrap.dedent(
2885-
"""\
2886-
'''Docstring'''
2887-
"""
2888-
)
2889-
node = parse(code)
2890-
with pytest.warns(DeprecationWarning) as records:
2891-
assert node.doc == "Docstring"
2892-
assert len(records) == 1
2893-
with pytest.warns(DeprecationWarning) as records:
2894-
node.doc = None
2895-
assert len(records) == 1
2896-
2897-
# If 'doc' isn't passed to Module, ClassDef, FunctionDef,
2898-
# no DeprecationWarning should be raised
2899-
doc_node = nodes.Const("Docstring")
2900-
with warnings.catch_warnings():
2901-
# Modify warnings filter to raise error for DeprecationWarning
2902-
warnings.simplefilter("error", DeprecationWarning)
2903-
node_module = nodes.Module(name="MyModule")
2904-
node_module.postinit(body=[], doc_node=doc_node)
2905-
assert node_module.doc_node == doc_node
2906-
node_class = nodes.ClassDef(
2907-
name="MyClass",
2908-
lineno=0,
2909-
col_offset=0,
2910-
end_lineno=0,
2911-
end_col_offset=0,
2912-
parent=nodes.Unknown(),
2913-
)
2914-
node_class.postinit(bases=[], body=[], decorators=[], doc_node=doc_node)
2915-
assert node_class.doc_node == doc_node
2916-
node_func = nodes.FunctionDef(
2917-
name="MyFunction",
2918-
lineno=0,
2919-
col_offset=0,
2920-
parent=node_module,
2921-
end_lineno=0,
2922-
end_col_offset=0,
2923-
)
2924-
node_func.postinit(
2925-
args=nodes.Arguments(parent=node_func, vararg=None, kwarg=None),
2926-
body=[],
2927-
doc_node=doc_node,
2928-
)
2929-
assert node_func.doc_node == doc_node
2930-
2931-
# Test 'doc' attribute if only 'doc_node' is passed
2932-
with pytest.warns(DeprecationWarning) as records:
2933-
assert node_module.doc == "Docstring"
2934-
assert len(records) == 1
2935-
with pytest.warns(DeprecationWarning) as records:
2936-
assert node_class.doc == "Docstring"
2937-
assert len(records) == 1
2938-
with pytest.warns(DeprecationWarning) as records:
2939-
assert node_func.doc == "Docstring"
2940-
assert len(records) == 1

0 commit comments

Comments
 (0)