diff options
author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2020-04-19 16:50:40 +0900 |
---|---|---|
committer | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2020-04-19 16:56:40 +0900 |
commit | a24ef1f0cc4ebc29871289b5b92d76f4fe7b7e80 (patch) | |
tree | 4d8ba32769224823724f547289561d8be4ccf922 /sphinx/pycode/ast.py | |
parent | 5c14375365fe9a9f7b97cc37988d17a8a3ec56d2 (diff) | |
download | sphinx-git-a24ef1f0cc4ebc29871289b5b92d76f4fe7b7e80.tar.gz |
refactor: Add Optional to type annotations
Diffstat (limited to 'sphinx/pycode/ast.py')
-rw-r--r-- | sphinx/pycode/ast.py | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/sphinx/pycode/ast.py b/sphinx/pycode/ast.py index c885db494..9664e7edb 100644 --- a/sphinx/pycode/ast.py +++ b/sphinx/pycode/ast.py @@ -58,7 +58,7 @@ def parse(code: str, mode: str = 'exec') -> "ast.AST": return ast.parse(code, mode=mode) -def unparse(node: ast.AST) -> str: +def unparse(node: Optional[ast.AST]) -> Optional[str]: """Unparse an AST to string.""" if node is None: return None @@ -138,7 +138,7 @@ def _unparse_arg(arg: ast.arg, default: Optional[ast.AST]) -> str: def unparse_arguments(node: ast.arguments) -> str: """Unparse an arguments to string.""" - defaults = list(node.defaults) + defaults = list(node.defaults) # type: List[Optional[ast.AST]] positionals = len(node.args) posonlyargs = 0 if hasattr(node, "posonlyargs"): # for py38+ @@ -147,7 +147,7 @@ def unparse_arguments(node: ast.arguments) -> str: for _ in range(len(defaults), positionals): defaults.insert(0, None) - kw_defaults = list(node.kw_defaults) + kw_defaults = list(node.kw_defaults) # type: List[Optional[ast.AST]] for _ in range(len(kw_defaults), len(node.kwonlyargs)): kw_defaults.insert(0, None) |