You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was searching for some typing inspection tools and found none that can both generate a python stub file (.pyi) and use the data from the runtime.
This is required in order to generate typing for dynamic method signatures, such as dataclasses' methods or manually changed function __signature__ property (i.e., via decoration).
Use Case
Let's assume we have a function func_1 that accepts three keyword-only parameters: k1, k2, and k3, with k1 being mandatory and k2 and k3 having their default values. Then, introduce function func_2 which, in addition to its own arguments, accepts **kwargs which then translates to the arguments of func_1:
We want to state that func_2 not only accepts the variable keyword arguments but expects exactly arguments of func_1.
There are several ways to do so, one requires manually listing all parameters in the @typing.overload or module stub, and the other requires runtime signature analysis.
However, both methods have their own problems: the first works fine when used in the same file with a small number of arguments but truly gets monstrous as either the number of arguments or the chain of calls rises, while the second one does not work with the static analyzers such as MyPy or PyCharm's inspector.
Thus, if pdoc would be able to process the source code files and result in the identical .pyi files which can be included in the wheel distribution, that would be perfect.
P.S.
Lately introduced PEP-612 solves this problem only partially, so I searched for a runtime code analyser and concluded that pdoc3 is the best solution for the problem (only a new exporter is required).
Hi
I was searching for some typing inspection tools and found none that can both generate a python stub file (
.pyi
) and use the data from the runtime.This is required in order to generate typing for dynamic method signatures, such as dataclasses' methods or manually changed function
__signature__
property (i.e., via decoration).Use Case
Let's assume we have a function
func_1
that accepts three keyword-only parameters:k1
,k2
, andk3
, withk1
being mandatory andk2
andk3
having their default values. Then, introduce functionfunc_2
which, in addition to its own arguments, accepts**kwargs
which then translates to the arguments offunc_1
:We want to state that
func_2
not only accepts the variable keyword arguments but expects exactly arguments offunc_1
.There are several ways to do so, one requires manually listing all parameters in the
@typing.overload
or module stub, and the other requires runtime signature analysis.Expected:
Options:
However, both methods have their own problems: the first works fine when used in the same file with a small number of arguments but truly gets monstrous as either the number of arguments or the chain of calls rises, while the second one does not work with the static analyzers such as MyPy or PyCharm's inspector.
Thus, if
pdoc
would be able to process the source code files and result in the identical.pyi
files which can be included in the wheel distribution, that would be perfect.P.S.
Lately introduced PEP-612 solves this problem only partially, so I searched for a runtime code analyser and concluded that
pdoc3
is the best solution for the problem (only a new exporter is required).Inspired by the discussion of python/typing#270
The text was updated successfully, but these errors were encountered: