Skip to content

Commit 179f219

Browse files
authored
change class instance attributes to be optional (#9)
Co-authored-by: David Andersson <[email protected]>
1 parent a90d8da commit 179f219

File tree

4 files changed

+331
-185
lines changed

4 files changed

+331
-185
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
## [Unreleased]
44

5+
## [v1.0.4] - 2023-01-13
6+
7+
### Changed
8+
9+
- Changed only class attributes to be required in class attributes section,
10+
instance attributes are now optional
11+
512
## [v1.0.3] - 2023-01-05
613

714
### Added
@@ -85,3 +92,4 @@
8592
[v1.0.1]: https://github.com/jdkandersson/flake8-docstrings-complete/releases/v1.0.1
8693
[v1.0.2]: https://github.com/jdkandersson/flake8-docstrings-complete/releases/v1.0.2
8794
[v1.0.3]: https://github.com/jdkandersson/flake8-docstrings-complete/releases/v1.0.3
95+
[v1.0.4]: https://github.com/jdkandersson/flake8-docstrings-complete/releases/v1.0.4

flake8_docstrings_complete/attrs.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -175,15 +175,14 @@ def check(
175175
Yields:
176176
All the problems with the attributes.
177177
"""
178-
all_targets = list(
179-
chain(_iter_class_attrs(class_assign_nodes), _iter_method_attrs(method_assign_nodes))
180-
)
181-
all_public_targets = list(
182-
target for target in all_targets if not target.name.startswith(PRIVATE_ATTR_PREFIX)
178+
all_class_targets = list(_iter_class_attrs(class_assign_nodes))
179+
all_public_class_targets = list(
180+
target for target in all_class_targets if not target.name.startswith(PRIVATE_ATTR_PREFIX)
183181
)
182+
all_targets = list(chain(all_class_targets, _iter_method_attrs(method_assign_nodes)))
184183

185184
# Check that attrs section is in docstring if function/ method has public attributes
186-
if all_public_targets and docstr_info.attrs is None:
185+
if all_public_class_targets and docstr_info.attrs is None:
187186
yield types_.Problem(
188187
docstr_node.lineno, docstr_node.col_offset, ATTRS_SECTION_NOT_IN_DOCSTR_MSG
189188
)
@@ -206,7 +205,7 @@ def check(
206205
# Check for class attributes that are not in the docstring
207206
yield from (
208207
types_.Problem(target.lineno, target.col_offset, ATTR_NOT_IN_DOCSTR_MSG % target.name)
209-
for target in all_public_targets
208+
for target in all_public_class_targets
210209
if target.name not in docstr_attrs
211210
)
212211

@@ -218,7 +217,7 @@ def check(
218217
)
219218

220219
# Check for empty attrs section
221-
if not all_public_targets and len(docstr_info.attrs) == 0:
220+
if not all_public_class_targets and len(docstr_info.attrs) == 0:
222221
yield types_.Problem(
223222
docstr_node.lineno, docstr_node.col_offset, ATTRS_SECTION_IN_DOCSTR_MSG
224223
)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "flake8-docstrings-complete"
3-
version = "1.0.3"
3+
version = "1.0.4"
44
description = "A linter that checks docstrings are complete"
55
authors = ["David Andersson <[email protected]>"]
66
license = "Apache 2.0"

0 commit comments

Comments
 (0)