mypy icon indicating copy to clipboard operation
mypy copied to clipboard

[stubgen] infer_sig_from_docstring fails with python3.12 inline generic

Open InvincibleRMC opened this issue 1 year ago • 2 comments

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

  • Mypy version used: 1.11.dev
  • Mypy command-line flags:
  • Mypy configuration options from mypy.ini (and other config files):
  • Python version used: python 3.10

InvincibleRMC avatar Jun 27 '24 17:06 InvincibleRMC

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

AlexWaygood avatar Jun 27 '24 20:06 AlexWaygood

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

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

InvincibleRMC avatar Jun 28 '24 13:06 InvincibleRMC