1

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:

  1. Wrap every function in python code

    def f(x: int, y: int) -> int:
        return _c_module(x, y)
    
  2. Maybe .pyi files could somehow do the trick(?)

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

@kebabdubai if this answer helped you or you like it, please do not forget to vote up and mark the answer as a solution, I would really appreciate it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.