55for a parameter. Once the body of the function is invoked, it is guaranteed that
66the validation was done on the parameter to make sure it matched one.
77
8- @recline.command(name="cake make")
9- def make_cake(flavor: Choices.define(["chocolate", "vanilla", "marble"])) -> None:
10- # We can assume flavor is one of the choices in the body of the function
8+ .. code-block:: python
9+
10+ @recline.command(name="cake make")
11+ def make_cake(flavor: Choices.define(["chocolate", "vanilla", "marble"])) -> None:
12+ # We can assume flavor is one of the choices in the body of the function
1113"""
1214
1315from typing import Callable
@@ -44,6 +46,7 @@ def define(
4446 the "*", "|", or ".." query characters. If these characters are
4547 present, then no validation will be done on the value (and validation
4648 is assumed to be done on whatever the command is calling)
49+
4750 data_type: The type of data that represents this argument
4851 """
4952
@@ -57,12 +60,12 @@ def validate(self, arg):
5760 )
5861 try :
5962 return data_type (arg )
60- except Exception : # pylint: disable=broad-except
63+ except Exception :
6164 raise ReclineTypeError (f'Unable to convert "{ arg } " to type { data_type } ' )
6265
6366 def choices (self , eager = False ):
6467 if hasattr (self .__class__ , '_cached_choices' ):
65- return self .__class__ ._cached_choices # pylint: disable=protected-access
68+ return self .__class__ ._cached_choices
6669
6770 # don't call the completer function unless we're sure we want to
6871 if not eager and not isinstance (available_choices , list ):
@@ -74,7 +77,7 @@ def choices(self, eager=False):
7477
7578 current_choices = [str (c ) for c in current_choices ]
7679 if cache_choices :
77- self .__class__ ._cached_choices = current_choices # pylint: disable=protected-access
80+ self .__class__ ._cached_choices = current_choices
7881 self .__class__ .metavar = f"<{ '|' .join (current_choices )} >"
7982 return current_choices
8083
0 commit comments