Skip to content

Commit

Permalink
add: Adds E110 catch-all for documentation not equal to its signature
Browse files Browse the repository at this point in the history
Raised if other errors have not been raised when docs not equal to sig
  • Loading branch information
jshwi committed Jul 10, 2022
1 parent f41b98e commit 4b1e181
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

[Unreleased](https://github.com/jshwi/docsig/compare/v0.13.0...HEAD)
------------------------------------------------------------------------
### Added
- add: Adds `E110` catch-all for documentation not equal to its signature

### Fixed
Fixes issue where `docsig -v` did not print version

Expand Down
1 change: 1 addition & 0 deletions docsig/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ def construct_func(func: _Function, report: _Report) -> _FuncStr:
func_str.add_param(arg, doc, kind, failed=True)
report.order(arg, doc)
report.incorrect(arg, doc)
report.not_equal(arg, doc)

if count + 1 != longest:
func_str.add_comma()
Expand Down
16 changes: 16 additions & 0 deletions docsig/_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def __init__(
self._disable = disable or []
self._disabled = False
self._resolve_targeted(targets or [])
self._errors: _t.List[str] = []

def _resolve_targeted(self, targets: _t.List[str]) -> None:
errors = [
Expand All @@ -46,6 +47,9 @@ def _lock(self, value: str) -> None:

def insert(self, index: int, value: str) -> None:
self._lock(value)
if value.startswith("E"):
self._errors.append(value)

message = getattr(_messages, value)
if not self._disabled and not (
value.startswith("E") and message in self
Expand Down Expand Up @@ -145,6 +149,18 @@ def incorrect(self, arg: str | None, doc: str | None) -> None:
if arg is None and doc is None:
self.append("E107")

def not_equal(self, arg: str | None, doc: str | None) -> None:
"""Final catch-all.
Only applies if no other errors, including disabled, have been
triggered
:param arg: Signature argument.
:param doc: Docstring argument.
"""
if arg is not None and doc is not None and not self._errors:
self.append("E110")

def get_report(self) -> str:
"""Get report compiled as a string.
Expand Down
2 changes: 2 additions & 0 deletions docsig/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
| E107: parameter appears to be incorrectly documented
| E108: return statement documented for property
| E109: cannot determine whether a return statement should exist or not
| E110: documented parameter not equal to its respective argument
"""
# Exxx: Error
# E1xx: Docstring
Expand All @@ -22,6 +23,7 @@
E107 = "E107: parameter appears to be incorrectly documented"
E108 = "E108: return statement documented for property"
E109 = "E109: cannot determine whether a return statement should exist or not"
E110 = "E110: documented parameter not equal to its respective argument"

# Hxxx: Hint
# H1xx: Docstring
Expand Down
18 changes: 18 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1115,3 +1115,21 @@ def function():
@property
def expected(self) -> str:
return messages.E109


@_templates.register
class _FailE110NE(_BaseTemplate):
@property
def template(self) -> str:
return """
def function(arg, param2) -> None:
\"\"\"Docstring.
:param param1: not equal.
:param para2: not equal.
\"\"\"
"""

@property
def expected(self) -> str:
return messages.E110
3 changes: 2 additions & 1 deletion whitelist.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
H102 # unused variable (docsig/messages.py:29)
H102 # unused variable (docsig/messages.py:31)
_.data # unused attribute (docsig/_repr.py:33)
_.data # unused attribute (docsig/_repr.py:62)
_.data # unused attribute (docsig/_repr.py:79)
Expand All @@ -17,6 +17,7 @@
_FailE109NoRetNoType # unused class (tests/__init__.py:254)
_FailE109WORetQuestion # unused class (tests/__init__.py:1106)
_FailE109WRetQuestion # unused class (tests/__init__.py:1089)
_FailE110NE # unused class (tests/__init__.py:1120)
_FailHintMissingReturn # unused class (tests/__init__.py:1001)
_FailIncorrectDoc # unused class (tests/__init__.py:374)
_FailIncorrectDocSum # unused class (tests/__init__.py:496)
Expand Down

0 comments on commit 4b1e181

Please sign in to comment.