Skip to content

argspec.kwonlyargs #86

@froh

Description

@froh

Hi, I have a function which takes a number of kwonlyargs and then arbitrary values (think file or directory names), like so:

import plac

def foo(*moo, gu=4, gac=None):
    print(f"{gu=}\n{gac=}\n{moo=}\n")

if __name__ == '__main__':


    plac.call(foo)

    P = plac.parser_from(foo)
    
    print(P.argspec)
    P.print_help()

this gives this output and seems to ignore the keyword-only arguments guand gac:

$ python .\plac_kwonlyargs.py --gu=77 foo bar
gu=4
gac=None
moo=('foo', 'bar', '--gu=77')

FullArgSpec(args=[], varargs='moo', varkw=None, defaults=None, kwonlyargs=['gu', 'gac'], kwonlydefaults={'gu': 4, 'gac': None}, annotations={})
usage: plac_kwonlyargs.py [-h] [moo ...]

positional arguments:
  moo

options:
  -h, --help  show this help message and exit

I'd expect the program to print

$ python .\plac_kwonlyargs.py --gu=77 foo bar
gu=77
gac=None
moo=('foo', 'bar')

FullArgSpec(args=[], varargs='moo', varkw=None, defaults=None, kwonlyargs=['gu', 'gac'], kwonlydefaults={'gu': 4, 'gac': None}, annotations={})
usage: plac_kwonlyargs.py [-h] [--gu=int] [--gac=Any] [moo ...]

positional arguments:
  moo
  gu    [4]
  gac   []

options:
  -h, --help  show this help message and exit

is this a pebcac on my side or intentional or a bug?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions