Skip to content

Commit

Permalink
Fix type errors stemming from getattr (#9889)
Browse files Browse the repository at this point in the history
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 <>
  • Loading branch information
hauntsaninja authored and Ivan Levkivskyi committed Jan 19, 2021
1 parent 9ceabe0 commit 75bb387
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion mypy/moduleinspect.py
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion mypy/stubdoc.py
Expand Up @@ -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
Expand Down

0 comments on commit 75bb387

Please sign in to comment.