From a24ef1f0cc4ebc29871289b5b92d76f4fe7b7e80 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Sun, 19 Apr 2020 16:50:40 +0900 Subject: refactor: Add Optional to type annotations --- sphinx/pycode/ast.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'sphinx/pycode') 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) -- cgit v1.2.1