From 75bb3879f0e7b8ec32c347c2c55467f677a203bd Mon Sep 17 00:00:00 2001 From: Shantanu <12621235+hauntsaninja@users.noreply.github.com> Date: Fri, 8 Jan 2021 03:12:19 -0800 Subject: [PATCH] Fix type errors stemming from getattr (#9889) Fixes #9888. I applied the following patch to typeshed and ran self check: ``` +@overload +def getattr(__o: Any, name: str, __default: None) -> Optional[Any]: ... +@overload def getattr(__o: Any, name: str, __default: Any = ...) -> Any: ... ``` Co-authored-by: hauntsaninja <> --- mypy/moduleinspect.py | 2 +- mypy/stubdoc.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mypy/moduleinspect.py b/mypy/moduleinspect.py index d54746260123..94491de4d804 100644 --- a/mypy/moduleinspect.py +++ b/mypy/moduleinspect.py @@ -45,7 +45,7 @@ def get_package_properties(package_id: str) -> ModuleProperties: package = importlib.import_module(package_id) except BaseException as e: raise InspectError(str(e)) from e - name = getattr(package, '__name__', None) + name = getattr(package, '__name__', package_id) file = getattr(package, '__file__', None) path = getattr(package, '__path__', None) # type: Optional[List[str]] if not isinstance(path, list): diff --git a/mypy/stubdoc.py b/mypy/stubdoc.py index 1baaaecfbdc8..040f44b29cba 100644 --- a/mypy/stubdoc.py +++ b/mypy/stubdoc.py @@ -202,7 +202,7 @@ def args_kwargs(signature: FunctionSig) -> bool: return list(sorted(self.signatures, key=lambda x: 1 if args_kwargs(x) else 0)) -def infer_sig_from_docstring(docstr: str, name: str) -> Optional[List[FunctionSig]]: +def infer_sig_from_docstring(docstr: Optional[str], name: str) -> Optional[List[FunctionSig]]: """Convert function signature to list of TypedFunctionSig Look for function signatures of function in docstring. Signature is a string of