Skip to content

Commit

Permalink
change class instance attributes to be optional (#9)
Browse files Browse the repository at this point in the history
Co-authored-by: David Andersson <[email protected]>
  • Loading branch information
jdkandersson and jdkandersson committed Jan 13, 2023
1 parent a90d8da commit 179f219
Show file tree
Hide file tree
Showing 4 changed files with 331 additions and 185 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

## [Unreleased]

## [v1.0.4] - 2023-01-13

### Changed

- Changed only class attributes to be required in class attributes section,
instance attributes are now optional

## [v1.0.3] - 2023-01-05

### Added
Expand Down Expand Up @@ -85,3 +92,4 @@
[v1.0.1]: https://github.com/jdkandersson/flake8-docstrings-complete/releases/v1.0.1
[v1.0.2]: https://github.com/jdkandersson/flake8-docstrings-complete/releases/v1.0.2
[v1.0.3]: https://github.com/jdkandersson/flake8-docstrings-complete/releases/v1.0.3
[v1.0.4]: https://github.com/jdkandersson/flake8-docstrings-complete/releases/v1.0.4
15 changes: 7 additions & 8 deletions flake8_docstrings_complete/attrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,15 +175,14 @@ def check(
Yields:
All the problems with the attributes.
"""
all_targets = list(
chain(_iter_class_attrs(class_assign_nodes), _iter_method_attrs(method_assign_nodes))
)
all_public_targets = list(
target for target in all_targets if not target.name.startswith(PRIVATE_ATTR_PREFIX)
all_class_targets = list(_iter_class_attrs(class_assign_nodes))
all_public_class_targets = list(
target for target in all_class_targets if not target.name.startswith(PRIVATE_ATTR_PREFIX)
)
all_targets = list(chain(all_class_targets, _iter_method_attrs(method_assign_nodes)))

# Check that attrs section is in docstring if function/ method has public attributes
if all_public_targets and docstr_info.attrs is None:
if all_public_class_targets and docstr_info.attrs is None:
yield types_.Problem(
docstr_node.lineno, docstr_node.col_offset, ATTRS_SECTION_NOT_IN_DOCSTR_MSG
)
Expand All @@ -206,7 +205,7 @@ def check(
# Check for class attributes that are not in the docstring
yield from (
types_.Problem(target.lineno, target.col_offset, ATTR_NOT_IN_DOCSTR_MSG % target.name)
for target in all_public_targets
for target in all_public_class_targets
if target.name not in docstr_attrs
)

Expand All @@ -218,7 +217,7 @@ def check(
)

# Check for empty attrs section
if not all_public_targets and len(docstr_info.attrs) == 0:
if not all_public_class_targets and len(docstr_info.attrs) == 0:
yield types_.Problem(
docstr_node.lineno, docstr_node.col_offset, ATTRS_SECTION_IN_DOCSTR_MSG
)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "flake8-docstrings-complete"
version = "1.0.3"
version = "1.0.4"
description = "A linter that checks docstrings are complete"
authors = ["David Andersson <[email protected]>"]
license = "Apache 2.0"
Expand Down
Loading

0 comments on commit 179f219

Please sign in to comment.