Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions src/click/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,11 @@ def __repr__(self) -> str:


class StringParamType(ParamType):
"""The text string type. Backed by the :data:`STRING` constant.
Converts values to Python :class:`str`. When reading from environment
variables, bytes are decoded using the filesystem encoding.
"""

name = "text"

def convert(
Expand Down Expand Up @@ -574,6 +579,16 @@ def __repr__(self) -> str:


class IntParamType(_NumberParamTypeBase):
"""The integer type. Backed by the :data:`INT` constant.
Converts values to Python :class:`int`.

.. code-block:: python

@click.command()
@click.option("--count", type=click.INT, default=1)
def cmd(count: int) -> None: ...
"""

name = "integer"
_number_class = int

Expand Down Expand Up @@ -608,6 +623,16 @@ def _clamp( # type: ignore


class FloatParamType(_NumberParamTypeBase):
"""The floating-point number type. Backed by the :data:`FLOAT` constant.
Converts values to Python :class:`float`.

.. code-block:: python

@click.command()
@click.option("--ratio", type=click.FLOAT, default=0.5)
def cmd(ratio: float) -> None: ...
"""

name = "float"
_number_class = float

Expand Down Expand Up @@ -659,6 +684,16 @@ def _clamp(self, bound: float, dir: t.Literal[1, -1], open: bool) -> float:


class BoolParamType(ParamType):
"""The boolean type. Backed by the :data:`BOOL` constant.
Converts truthy string values (e.g. ``"1"``, ``"yes"``, ``"true"``,
``"on"``) to :data:`True` and falsy strings (e.g. ``"0"``, ``"no"``,
``"false"``, ``"off"``) to :data:`False`.

Primarily used for boolean flags and environment variables rather than
plain options; Click automatically uses this type for
:func:`option` calls with ``is_flag=True``.
"""

name = "boolean"

bool_states: dict[str, bool] = {
Expand Down Expand Up @@ -728,6 +763,12 @@ def __repr__(self) -> str:


class UUIDParameterType(ParamType):
"""The UUID type. Backed by the :data:`UUID` constant.
Converts string values to :class:`uuid.UUID` objects. Accepts standard
UUID representations including hyphenated (``"xxxxxxxx-xxxx-..."``) and
compact forms.
"""

name = "uuid"

def convert(
Expand Down
Loading