0

If I have these two functions:

def foo(code:int, *args, **kwargs):
    if code == 1:
        bar(*args, **kwargs)
    else:
        return None

def bar(a:str, b:int, c:int=1, d:int=2):
    pass

I want users can see what argument can be passed to foo, just like if I define foo like:

def foo(code:int, a:str, b:int, c:int=1, d:int=2):
    if code == 1:
        bar(a, b, c, d)
    else:
        return None

What can I do to inherit bar's argument in foo

ParamSpec is almost there but not enough for my situation, foo has one more argumnt: code than bar.

PaleNeutron
  • 2,543
  • 4
  • 25
  • 43
  • "can see" how? If you're asking about an IDE, you should specify the IDE. If you're asking about type hints, [`ParamSpec`](https://peps.python.org/pep-0612/) may be able to help, though it's a fairly new feature. – Silvio Mayolo Apr 17 '23 at 03:15
  • @SilvioMayolo, may be either of the main ide: vscode, pycharm and jupyter. But currently I think none of them can directly show the arguments without changing my code. I'll look into ParamSpec. – PaleNeutron Apr 17 '23 at 03:24
  • @SilvioMayolo, I found `TypedDict` is almost what I'am looking for but arguments in `TypedDict` can not have default value, how to resolve that? – PaleNeutron Apr 17 '23 at 06:12

0 Answers0