Skip to content

Format

ToString

Bases: Protocol

Represents types that can be converted to strings.

Source code in src/wraps/parse/format.py
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
@runtime_checkable
class ToString(Protocol):
    """Represents types that can be converted to strings."""

    @required
    def to_string(self) -> str:
        """Converts `self` to its string representation.

        Returns:
            The string representation of `self`.
        """
        ...

    def to_short_string(self) -> str:
        """Converts `self` to its (short) string representation.

        The default implementation simply calls [`to_string`][wraps.parse.format.ToString.to_string].

        Returns:
            The (short) string representation of `self`.
        """
        return self.to_string()

    def __str__(self) -> str:
        """Calls [`to_string`][wraps.parse.format.ToString.to_string] and returns the result.

        Returns:
            The string representation of `self`.
        """
        return self.to_string()

to_string() -> str

Converts self to its string representation.

Returns:

Type Description
str

The string representation of self.

Source code in src/wraps/parse/format.py
14
15
16
17
18
19
20
21
@required
def to_string(self) -> str:
    """Converts `self` to its string representation.

    Returns:
        The string representation of `self`.
    """
    ...

to_short_string() -> str

Converts self to its (short) string representation.

The default implementation simply calls to_string.

Returns:

Type Description
str

The (short) string representation of self.

Source code in src/wraps/parse/format.py
23
24
25
26
27
28
29
30
31
def to_short_string(self) -> str:
    """Converts `self` to its (short) string representation.

    The default implementation simply calls [`to_string`][wraps.parse.format.ToString.to_string].

    Returns:
        The (short) string representation of `self`.
    """
    return self.to_string()

__str__() -> str

Calls to_string and returns the result.

Returns:

Type Description
str

The string representation of self.

Source code in src/wraps/parse/format.py
33
34
35
36
37
38
39
def __str__(self) -> str:
    """Calls [`to_string`][wraps.parse.format.ToString.to_string] and returns the result.

    Returns:
        The string representation of `self`.
    """
    return self.to_string()

to_string(value: ToString) -> str

Calls to_string method on the given value and returns the result.

Parameters:

Name Type Description Default
value ToString

The value to convert to string.

required

Returns:

Type Description
str

The string representation of value.

Source code in src/wraps/parse/format.py
42
43
44
45
46
47
48
49
50
51
52
def to_string(value: ToString) -> str:
    """Calls [`to_string`][wraps.parse.format.ToString.to_string] method on the given value
    and returns the result.

    Arguments:
        value: The value to convert to string.

    Returns:
        The string representation of `value`.
    """
    return value.to_string()

to_short_string(value: ToString) -> str

Calls to_short_string method on the given value and returns the result.

Parameters:

Name Type Description Default
value ToString

The value to convert to string.

required

Returns:

Type Description
str

The (short) string representation of value.

Source code in src/wraps/parse/format.py
55
56
57
58
59
60
61
62
63
64
65
def to_short_string(value: ToString) -> str:
    """Calls [`to_short_string`][wraps.parse.format.ToString.to_short_string] method
    on the given value and returns the result.

    Arguments:
        value: The value to convert to string.

    Returns:
        The (short) string representation of `value`.
    """
    return value.to_short_string()