Reputation: 67
How can I define a function, or a contructor for a class with specified arguments using the C API?
By default function takes PyObject*
args, and later in the code the linter won’t show real arguments.
If it’s not possible, is there a way to bypass it? I came up with two possible options:
Wrap every function in python code
def f(x: int, y: int) -> int:
return _c_module(x, y)
Maybe .pyi
files could somehow do the trick(?)
Upvotes: 1
Views: 111
Reputation: 1453
The best way to do this is to use .pyi
files and distribute them with your package (look at the docs), i.e. if you have a module my_mod
with class Baz
with member foo
and method bar
, then you would want to have my_mod.pyi
like this:
class Baz:
foo: float
def bar(self, param_a: str, default_one: int = ...) -> str:
pass
And then most linters, type checkers, etc. would catch this up and work with it.
Additionally: about stubs from mypy.
Upvotes: 2