Skip to content

Commit 566898a

Browse files
[3.12] gh-120661: improve example for basic type hints (GH-120934) (#120988)
gh-120661: improve example for basic type hints (GH-120934) (cherry picked from commit bb057ea) Co-authored-by: Bénédikt Tran <[email protected]>
1 parent 433a5f8 commit 566898a

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

Doc/library/typing.rst

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,13 @@ This module provides runtime support for type hints.
2727

2828
Consider the function below::
2929

30-
def moon_weight(earth_weight: float) -> str:
31-
return f'On the moon, you would weigh {earth_weight * 0.166} kilograms.'
30+
def surface_area_of_cube(edge_length: float) -> str:
31+
return f"The surface area of the cube is {6 * edge_length ** 2}."
3232

33-
The function ``moon_weight`` takes an argument expected to be an instance of :class:`float`,
34-
as indicated by the *type hint* ``earth_weight: float``. The function is expected to
35-
return an instance of :class:`str`, as indicated by the ``-> str`` hint.
33+
The function ``surface_area_of_cube`` takes an argument expected to
34+
be an instance of :class:`float`, as indicated by the :term:`type hint`
35+
``edge_length: float``. The function is expected to return an instance
36+
of :class:`str`, as indicated by the ``-> str`` hint.
3637

3738
While type hints can be simple classes like :class:`float` or :class:`str`,
3839
they can also be more complex. The :mod:`typing` module provides a vocabulary of

0 commit comments

Comments
 (0)