Skip to content

Commit

Permalink
fix: Fixes returning of non-subscript types
Browse files Browse the repository at this point in the history
Returning `Any` no longer processed as None
  • Loading branch information
jshwi committed Jun 21, 2022
1 parent a1fbae2 commit 889d823
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Changed
- Updates syntax highlighting

### Fixed
- Fixes returning of non-subscript types

[0.5.0](https://github.com/jshwi/docsig/releases/tag/v0.5.0) - 2022-06-21
------------------------------------------------------------------------
### Added
Expand Down
3 changes: 3 additions & 0 deletions docsig/_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ def _get_returns(self) -> None:
if isinstance(self._func.returns, _ast.Name):
self._returns = self._func.returns.id

elif isinstance(self._func.returns, _ast.Attribute):
self._returns = self._func.returns.attr

elif isinstance(self._func.returns, _ast.Subscript):
if isinstance(self._func.returns.value, _ast.Name):
self._returns = self._func.returns.value.id
Expand Down
20 changes: 20 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -812,3 +812,23 @@ def function(reduce: bool = False) -> _t.Tuple[str, ...]:
@property
def expected(self) -> str:
return ""


@_templates.register
class _PassReturnAny(_BaseTemplate):
@property
def template(self) -> str:
return """
def function(*args: _t.Any, **kwargs: bool) -> _t.Any:
\"\"\"Proper docstring.
:param args: Manipulate string(s).
:key format: Return a string instead of a tuple if strings are
passed as tuple.
:return: Colored string or None.
\"\"\"
"""

@property
def expected(self) -> str:
return ""
1 change: 1 addition & 0 deletions whitelist.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
_PassOnlyParams # unused class (tests/__init__.py:799)
_PassParam # unused class (tests/__init__.py:24)
_PassRetType # unused class (tests/__init__.py:170)
_PassReturnAny # unused class (tests/__init__.py:817)
_PassUnderscoreParam # unused class (tests/__init__.py:124)
_PassWithArgs # unused class (tests/__init__.py:511)
_PassWithKwargs # unused class (tests/__init__.py:556)
Expand Down

0 comments on commit 889d823

Please sign in to comment.