You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a script with several subcommands where the main command reads from a config file to populate the context object, and the subcommands then operate on this data in the object. Here's an MVCE:
Unfortunately, the shell completion for EntityType isn't working; when it gets triggered, the script fails with:
Traceback (most recent call last):
File "/Users/jwodder/.local/virtualenvwrapper/venvs/tmp-c51a37fb0e04aa3/bin/obj-complete", line 8, in <module>
sys.exit(main())
File "/Users/jwodder/.local/virtualenvwrapper/venvs/tmp-c51a37fb0e04aa3/lib/python3.9/site-packages/click/core.py", line 1128, in __call__
return self.main(*args, **kwargs)
File "/Users/jwodder/.local/virtualenvwrapper/venvs/tmp-c51a37fb0e04aa3/lib/python3.9/site-packages/click/core.py", line 1048, in main
self._main_shell_completion(extra, prog_name, complete_var)
File "/Users/jwodder/.local/virtualenvwrapper/venvs/tmp-c51a37fb0e04aa3/lib/python3.9/site-packages/click/core.py", line 1123, in _main_shell_completion
rv = shell_complete(self, ctx_args, prog_name, complete_var, instruction)
File "/Users/jwodder/.local/virtualenvwrapper/venvs/tmp-c51a37fb0e04aa3/lib/python3.9/site-packages/click/shell_completion.py", line 49, in shell_complete
echo(comp.complete())
File "/Users/jwodder/.local/virtualenvwrapper/venvs/tmp-c51a37fb0e04aa3/lib/python3.9/site-packages/click/shell_completion.py", line 291, in complete
completions = self.get_completions(args, incomplete)
File "/Users/jwodder/.local/virtualenvwrapper/venvs/tmp-c51a37fb0e04aa3/lib/python3.9/site-packages/click/shell_completion.py", line 273, in get_completions
return obj.shell_complete(ctx, incomplete)
File "/Users/jwodder/.local/virtualenvwrapper/venvs/tmp-c51a37fb0e04aa3/lib/python3.9/site-packages/click/core.py", line 2393, in shell_complete
return self.type.shell_complete(ctx, self, incomplete)
File "/Users/jwodder/.local/virtualenvwrapper/venvs/tmp-c51a37fb0e04aa3/lib/python3.9/site-packages/obj_complete.py", line 23, in shell_complete
return [CompletionItem(c) for c in ctx.obj.entities if c.startswith(incomplete)]
AttributeError: 'NoneType' object has no attribute 'entities'
Is there a way to get the ctx.obj assignment in main() to be in effect when completing arguments for subcommands?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Python: 3.9.9
Click: 8.0.3
I have a script with several subcommands where the main command reads from a config file to populate the context object, and the subcommands then operate on this data in the object. Here's an MVCE:
Unfortunately, the shell completion for
EntityType
isn't working; when it gets triggered, the script fails with:Is there a way to get the
ctx.obj
assignment inmain()
to be in effect when completing arguments for subcommands?Beta Was this translation helpful? Give feedback.
All reactions