-
Notifications
You must be signed in to change notification settings - Fork 192
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FIX: Do not evaluate callable defaults during tab-completion
- Loading branch information
1 parent
b6f7ec1
commit e265067
Showing
4 changed files
with
39 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# -*- coding: utf-8 -*- | ||
########################################################################### | ||
# Copyright (c), The AiiDA team. All rights reserved. # | ||
# This file is part of the AiiDA code. # | ||
# # | ||
# The code is hosted on GitHub at https://github.com/aiidateam/aiida-core # | ||
# For further information on the license, see the LICENSE.txt file # | ||
# For further information please visit http://www.aiida.net # | ||
########################################################################### | ||
""" | ||
.. py:module::callable | ||
:synopsis: A monkey-patched subclass of click.Option that does not evaluate callable default during tab completion | ||
""" | ||
|
||
import typing as t | ||
|
||
import click | ||
|
||
__all__ = ('CallableDefaultOption',) | ||
|
||
|
||
class CallableDefaultOption(click.Option): | ||
"""A monkeypatch for click.Option that does not evaluate default callbacks during tab completion | ||
This is a temporary solution until a proper fix is implemented in click, see: | ||
https://github.com/pallets/click/issues/2614 | ||
""" | ||
|
||
def get_default(self, ctx: click.Context, call: bool = True) -> t.Optional[t.Union[t.Any, t.Callable[[], t.Any]]]: | ||
"""provides the functionality of :meth:`click.Option.get_default`, | ||
but ensures we do not evaluate callable defaults when in tab-completion context.""" | ||
if ctx.resilient_parsing: | ||
return None | ||
return super().get_default(ctx=ctx, call=call) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters