mypy
mypy copied to clipboard
Stubgen infers wrong from doctest blocks
Bug Report
(A clear and concise description of what the bug is.) When generating stub for a C extension, the doctest blocks are parsed and creates a wrong overload.
Example :
>>> class example():
... def init(self):
... pass
>>> ex = example()
>>> ex.init()
>>>
To Reproduce
(Write your steps here:)
- Clone the following repository : https://github.com/jbstand/stubgen-issue-example
-
pip install . - Use stubgen to generate stubs from the module :
stubgen -m example - Observe init type overloaded by type without self argument from doctest.
Expected Behavior
(Write what you thought would happen.) Stubgen should only take the first line of the docstring which is the type annotation as docstring or understand self is passed as it is for every class method.
Actual Behavior
(Write what happened.) The following two stubs get generated with the second causing typing conflicts because one version doesn't expect self.
from typing import Any
from typing import overload
class example:
def __init__(self, *args, **kwargs) -> None: ...
@overload
def init(self) -> None: ...
@overload
def init() -> Any: ...
Your Environment
- Mypy version used: 0.971
- Mypy command-line flags:
stubgen -m ex_module - Mypy configuration options from
mypy.ini(and other config files): - Python version used: Python 3.8.5 also tested in latest 3.10 minor as part of a recurrent CI pipeline
- Operating system and version: Windows 10 and alpine as part of CI