]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-120661: improve example for basic type hints (#120934)
authorBénédikt Tran <10796600+picnixz@users.noreply.github.com>
Tue, 25 Jun 2024 07:59:56 +0000 (09:59 +0200)
committerGitHub <noreply@github.com>
Tue, 25 Jun 2024 07:59:56 +0000 (07:59 +0000)
Doc/library/typing.rst

index 07b6e342e09195d4b9652997e61abacb21e3a21d..7d1d317b9f8f8a234e4a09f9a978f99c2601db91 100644 (file)
@@ -27,12 +27,13 @@ This module provides runtime support for type hints.
 
 Consider the function below::
 
-   def moon_weight(earth_weight: float) -> str:
-       return f'On the moon, you would weigh {earth_weight * 0.166} kilograms.'
+   def surface_area_of_cube(edge_length: float) -> str:
+       return f"The surface area of the cube is {6 * edge_length ** 2}."
 
-The function ``moon_weight`` takes an argument expected to be an instance of :class:`float`,
-as indicated by the *type hint* ``earth_weight: float``. The function is expected to
-return an instance of :class:`str`, as indicated by the ``-> str`` hint.
+The function ``surface_area_of_cube`` takes an argument expected to
+be an instance of :class:`float`, as indicated by the :term:`type hint`
+``edge_length: float``. The function is expected to return an instance
+of :class:`str`, as indicated by the ``-> str`` hint.
 
 While type hints can be simple classes like :class:`float` or :class:`str`,
 they can also be more complex. The :mod:`typing` module provides a vocabulary of