Unexpected keyword argument in python click

It seems that you try to call plot_map_from_nc or plot_glm with actual arguments somewhere in your code like this:

plot_map_from_nc(any_time_data=False)
plot_glm(any_time_data=False)

which will generate the same error message that you got.

  File "testClick.py", line 39, in <module>
    plot_glm(any_time_data=False)
  File "c:\winPython\python-2.7.10.amd64\lib\site-packages\click\core.py", line 716, in __call__
    return self.main(*args, **kwargs)
  File "c:\winPython\python-2.7.10.amd64\lib\site-packages\click\core.py", line 695, in main
    with self.make_context(prog_name, args, **extra) as ctx:
  File "c:\winPython\python-2.7.10.amd64\lib\site-packages\click\core.py", line 618, in make_context
    ctx = Context(self, info_name=info_name, parent=parent, **extra)
TypeError: __init__() got an unexpected keyword argument 'any_time_data'

Reason for the error

That is because plot_map_from_nc and plot_glm are not normal functions after those click decorators. They are callable objects, whose signature becomes

plot_map_from_nc(args=None, prog_name=None, complete_var=None, standalone_mode=True, **extra)

The type of plot_map_from_nc is click.core.Command and every arguments passed to it will be redirected to click.core.Command.main()

Solution

The correct way to invoke these callable objects is

plot_map_from_nc(sys.argv[1:]) # or
plot_map_from_nc()

If you want to use plot_map_from_nc normally in your code, define it with a different name:

def __plot_map_from_nc__(... , any_time_data=True, ...):
    do_your_job_here
# create an alias
plot_map_from_nc = __plot_map_from_nc__ 
# pass this alias to click
@plot_glm.command()
@click.argument('path_nc') # ...
@click.option('--xaxis_min', default=0.0, help='') # ...
plot_map_from_nc

# Now  plot_map_from_nc becomes a   'click.core.Command'   object  while
# __plot_map_from_nc__ is still a normal function which can be invoke as
__plot_map_from_nc__(... , any_time_data=True, ...)

I did a little digging. Sometimes the best place to look is in the code that gave you the error: https://github.com/pallets/click/blob/0d48b2fbd256c1c692e3f3ba4c22b102f21f82f7/click/core.py#L879

if args and not ctx.allow_extra_args and not ctx.resilient_parsing:
    ctx.fail('Got unexpected extra argument%s (%s)'
             % (len(args) != 1 and 's' or '',
                ' '.join(map(make_str, args))))

So What I think is that you need to set the allow_extra_args=True or resilient_parsing=True

By default they are:

resilient_parsing=False, allow_extra_args=None,

https://github.com/pallets/click/blob/0d48b2fbd256c1c692e3f3ba4c22b102f21f82f7/click/core.py#L196

If you want, test it out by commenting out that one, I bet that the error you get will be from annotate_date (next alphabetically)