diff --git a/mypy/fastparse.py b/mypy/fastparse.py index 4a0e34d7ba149..688cd9b20928d 100644 --- a/mypy/fastparse.py +++ b/mypy/fastparse.py @@ -74,7 +74,7 @@ def parse(source: Union[str, bytes], module: Optional[str], errors: Optional[Errors] = None, options: Optional[Options] = None, - plugin: Plugin = None ) -> MypyFile: + plugin: Optional[Plugin] = None) -> MypyFile: """Parse a source file, without doing any semantic analysis. @@ -87,6 +87,8 @@ def parse(source: Union[str, bytes], raise_on_error = True if options is None: options = Options() + if plugin is None: + plugin = Plugin(options) errors.set_file(fnam, module) is_stub_file = fnam.endswith('.pyi') try: @@ -137,8 +139,9 @@ def parse_docstring(hook: Callable[[DocstringParserContext], TypeMap], docstring """ type_map = hook(DocstringParserContext(docstring, line, errors)) if type_map: - arg_types = [type_map.pop(name, AnyType()) for name in arg_names] - return_type = type_map.pop('return', AnyType()) + arg_types = [type_map.pop(name, AnyType(TypeOfAny.unannotated)) + for name in arg_names] + return_type = type_map.pop('return', AnyType(TypeOfAny.unannotated)) if type_map: errors.report(line, 0, TYPE_COMMENT_DOCSTRING_ERROR.format(list(type_map))) diff --git a/mypy/fastparse2.py b/mypy/fastparse2.py index 5c1bb8b9d890b..6ebcc339d77e5 100644 --- a/mypy/fastparse2.py +++ b/mypy/fastparse2.py @@ -83,7 +83,7 @@ def parse(source: Union[str, bytes], module: Optional[str], errors: Optional[Errors] = None, options: Optional[Options] = None, - plugin: Plugin = None) -> MypyFile: + plugin: Optional[Plugin] = None) -> MypyFile: """Parse a source file, without doing any semantic analysis. Return the parse tree. If errors is not provided, raise ParseError @@ -95,6 +95,8 @@ def parse(source: Union[str, bytes], raise_on_error = True if options is None: options = Options() + if plugin is None: + plugin = Plugin(options) errors.set_file(fnam, module) is_stub_file = fnam.endswith('.pyi') try: diff --git a/mypy/parse.py b/mypy/parse.py index a1fd8fe0f0059..cdfadde25dfba 100644 --- a/mypy/parse.py +++ b/mypy/parse.py @@ -11,7 +11,7 @@ def parse(source: Union[str, bytes], module: Optional[str], errors: Optional[Errors], options: Options, - plugin: Plugin) -> MypyFile: + plugin: Optional[Plugin]) -> MypyFile: """Parse a source file, without doing any semantic analysis. Return the parse tree. If errors is not provided, raise ParseError diff --git a/mypy/plugin.py b/mypy/plugin.py index 5dbe05ec709d8..ff70a7111c26b 100644 --- a/mypy/plugin.py +++ b/mypy/plugin.py @@ -125,6 +125,7 @@ def fail(self, msg: str, ctx: Context, serious: bool = False, *, ('cls', ClassDef), # The class definition ('reason', Expression), # The expression being applied (decorator, metaclass, base class) ('api', SemanticAnalyzerPluginInterface) + ]) # A context for a hook that extracts type annotations from docstrings. #