The built-in dataclass decorator programmatically creates the __init__ function, where PyCharm still seems to be recognizing its signature and giving a help message (e.g., Cmd+P shows the list of parameters that __init__ takes).
Can I have this for other programmatically created functions in PyCharm?
For example, if I create a meta class as follows:
from dataclasses import dataclass
class MyMeta(type):
def __new__(mcs, name, bases, namespace, **kwargs):
return dataclass(super().__new__(mcs, name, bases, namespace, **kwargs))
class Test(metaclass=MyMeta):
a: int = 1
b: float = 2.0
t = Test(b=3.0)
Pycharm does not give a proper help message with the last line (also raises warning), in contrast with the typical decorator-use of the dataclass. This seems to be the matter of Pycharm since inspect.signature gives the correct signature of __init__. Is there a way to fix this?