Proper pep695 generic function docstrings#5743
Proper pep695 generic function docstrings#5743InvincibleRMC wants to merge 9 commits intopybind:masterfrom
Conversation
|
@timohl if you have any comments/suggestions please let me know. |
|
I should find time to review the code in more detail during the weekend, but I already skimmed through the tests and the new syntax looks nice. :) One thing that came to my mind though is backwards compatibility. Also, what is the impact of the check for |
From what I can tell mypy's stubgen or pybind11-stubgen currently ignore the inside of pep695. Mypy has a todo. Mypy will fail if running in version less than 3.12 def foo[T](a: T) -> T: ... # invalid syntaxHowever, mypy could when implementing support generate pre-pep695 syntax in stubs when ran on older python versions. import typing
T = typing.TypeVar("T")
def foo(a: T) -> T: ... # valid |
|
I don't know how much this would get used but it would be a nice addition to pybind11. I added very basic support for this syntax to my fork of pybind11-stubgen. It only supports the un-type-hinted variant. Looks like the tests are failing due to our changes to type hints. |
Description
Add
typevar_recordto hold information about function type variables. Use these type variables to update the generated docstrings as according to pep695.To be used in conjuction with the typevar types introduced in #5167.
Suggested changelog entry:
typevar_recordto add pep695 generics to function docstrings.