class documentation

class ParamType:

Known subclasses: click.types.Choice, click.types.DateTime, click.types.File, click.types.Path, click.types._NumberParamTypeBase, click.types.BoolParamType, click.types.CompositeParamType, click.types.FuncParamType, click.types.StringParamType, click.types.UnprocessedParamType, click.types.UUIDParameterType

View In Hierarchy

Represents the type of a parameter. Validates and converts values from the command line or Python into the correct type.

To implement a custom type, subclass and implement at least the following:

  • The name class attribute must be set.
  • Calling an instance of the type with None must return None. This is already implemented by default.
  • convert must convert string values to the correct type.
  • convert must accept values that are already the correct type.
  • It must be able to convert a value if the ctx and param arguments are None. This can occur when converting prompt input.
Method __call__ Undocumented
Method convert Convert the value to the correct type. This is not called if the value is None (the missing value).
Method fail Helper method to fail with an invalid value message.
Method get​_metavar Returns the metavar default for this param if it provides one.
Method get​_missing​_message Optionally might return extra information about a missing parameter.
Method shell​_complete No summary
Method split​_envvar​_value Given a value from an environment variable this splits it up into small chunks depending on the defined envvar list splitter.
Method to​_info​_dict Gather information that could be useful for a tool generating user-facing documentation.
Class Variable arity Undocumented
Class Variable envvar​_list​_splitter Undocumented
Class Variable is​_composite Undocumented
Class Variable name Undocumented
def __call__(self, value, param=None, ctx=None):

Undocumented

Parameters
value:t.AnyUndocumented
param:t.Optional[Parameter]Undocumented
ctx:t.Optional[Context]Undocumented
Returns
t.AnyUndocumented
def convert(self, value, param, ctx):

Convert the value to the correct type. This is not called if the value is None (the missing value).

This must accept string values from the command line, as well as values that are already the correct type. It may also convert other compatible types.

The param and ctx arguments may be None in certain situations, such as when converting prompt input.

If the value cannot be converted, call fail with a descriptive message.

Parameters
value:t.AnyThe value to convert.
param:t.Optional[Parameter]The parameter that is using this type to convert its value. May be None.
ctx:t.Optional[Context]The current context that arrived at this value. May be None.
Returns
t.AnyUndocumented
def fail(self, message, param=None, ctx=None):
Helper method to fail with an invalid value message.
Parameters
message:strUndocumented
param:t.Optional[Parameter]Undocumented
ctx:t.Optional[Context]Undocumented
Returns
t.NoReturnUndocumented
def get_metavar(self, param):
Returns the metavar default for this param if it provides one.
Parameters
param:ParameterUndocumented
Returns
t.Optional[str]Undocumented
def get_missing_message(self, param):
overridden in click.types.Choice

Optionally might return extra information about a missing parameter.

New in version 2.0.
Parameters
param:ParameterUndocumented
Returns
t.Optional[str]Undocumented
def shell_complete(self, ctx, param, incomplete):

Return a list of ~click.shell_completion.CompletionItem objects for the incomplete value. Most types do not provide completions, but some do, and this allows custom types to provide custom completions as well.

New in version 8.0.
Parameters
ctx:ContextInvocation context for this command.
param:ParameterThe parameter that is requesting completion.
incomplete:strValue being completed. May be empty.
Returns
t.List[CompletionItem]Undocumented
def split_envvar_value(self, rv):

Given a value from an environment variable this splits it up into small chunks depending on the defined envvar list splitter.

If the splitter is set to None, which means that whitespace splits, then leading and trailing whitespace is ignored. Otherwise, leading and trailing splitters usually lead to empty items being included.

Parameters
rv:strUndocumented
Returns
t.Sequence[str]Undocumented
def to_info_dict(self):

Gather information that could be useful for a tool generating user-facing documentation.

Use click.Context.to_info_dict to traverse the entire CLI structure.

New in version 8.0.
Returns
t.Dict[str, t.Any]Undocumented
arity: t.ClassVar[int] =

Undocumented

envvar_list_splitter: t.ClassVar[t.Optional[str]] =

Undocumented

is_composite: t.ClassVar[bool] =

Undocumented