From 889d823acfef0201cc7a6d40f4c8ee7a8cc8efc0 Mon Sep 17 00:00:00 2001 From: jshwi Date: Tue, 21 Jun 2022 21:03:46 +1000 Subject: [PATCH] fix: Fixes returning of non-subscript types Returning `Any` no longer processed as None --- CHANGELOG.md | 3 +++ docsig/_function.py | 3 +++ tests/__init__.py | 20 ++++++++++++++++++++ whitelist.py | 1 + 4 files changed, 27 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 50610568..dba582aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/docsig/_function.py b/docsig/_function.py index b3c59803..db31aa6f 100644 --- a/docsig/_function.py +++ b/docsig/_function.py @@ -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 diff --git a/tests/__init__.py b/tests/__init__.py index b61691c3..89b21fed 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -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 "" diff --git a/whitelist.py b/whitelist.py index 10f49dd5..30145887 100644 --- a/whitelist.py +++ b/whitelist.py @@ -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)