summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2024-06-25 08:25:29 (GMT)
committerGitHub <noreply@github.com>2024-06-25 08:25:29 (GMT)
commit6cddf1a611e5656c11968ae6760736165d6c73ff (patch)
tree55f93da0d7fe721eab792fa9b7f6ab66b7810605
parentd26ce50f7bd59aa0bf6d1659ff96fb3a9075ff38 (diff)
downloadcpython-6cddf1a611e5656c11968ae6760736165d6c73ff.zip
cpython-6cddf1a611e5656c11968ae6760736165d6c73ff.tar.gz
cpython-6cddf1a611e5656c11968ae6760736165d6c73ff.tar.bz2
[3.13] gh-120661: improve example for basic type hints (GH-120934) (#120987)
gh-120661: improve example for basic type hints (GH-120934) (cherry picked from commit bb057ea1075e000ff3f0d6b27a2b7ca4117b4969) Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
-rw-r--r--Doc/library/typing.rst11
1 files changed, 6 insertions, 5 deletions
diff --git a/Doc/library/typing.rst b/Doc/library/typing.rst
index 8e334e9..53fe6dd 100644
--- a/Doc/library/typing.rst
+++ b/Doc/library/typing.rst
@@ -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