python / mypy

Optional static typing for Python
https://www.mypy-lang.org/
Other
17.85k stars 2.74k forks source link

[stubgen] infer_sig_from_docstring fails with python3.12 inline generic #17447

Open InvincibleRMC opened 5 days ago

InvincibleRMC commented 5 days ago

Bug Report

Trying to infer types from docstrings with python3.12 inline generics fails to generate.

To Reproduce

from mypy.stubdoc import infer_sig_from_docstring
infer_sig_from_docstring('\nfunc[T, V](x: T, y: V) -> T', 'func')

Expected Behavior

infer_sig_from_docstring('\nfunc[T, V](x: T, y: V) -> T', 'func') ==
            [
                FunctionSig(
                    name="func", args=[ArgSig(name="x", type="T"), ArgSig(name="y", type="V")], ret_type="T"
                )
            ]

Actual Behavior

infer_sig_from_docstring('\nfunc[T, V](x: T, y: V) -> T', 'func') == []

Your Environment

AlexWaygood commented 5 days ago

@hamdanal, might be of interest to you? :)

InvincibleRMC commented 4 days ago

Following up it would be very helpful if stubgen could generate the following automatically

from typing import TypeVar
T = TypeVar("T")