New submission from Edward Yang <ezy...@mit.edu>:
Consider the following program: ``` import inspect from typing import Generic, TypeVar T = TypeVar('T') class A(Generic[T]): def __init__(self) -> None: pass print(inspect.signature(A)) ``` I expect inspect.signature to return () as the signature of the constructor of this function. However, I get this: ``` $ python3 foo.py (*args, **kwds) ``` Although it is true that one cannot generally rely on inspect.signature to always give the most accurate signature (because there may always be decorator or metaclass shenanigans getting in the way), in this particular case it seems especially undesirable because Python type annotations are supposed to be erased at runtime, and yet here inheriting from Generic (simply to add type annotations) causes a very clear change in runtime behavior. ---------- components: Library (Lib) messages: 370870 nosy: ezyang priority: normal severity: normal status: open title: Inheriting from Generic causes inspect.signature to always return (*args, **kwargs) for constructor (and all subclasses) type: behavior versions: Python 3.9 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue40897> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com