From 67f62826974789a968586aa2a097437c4e8eaf86 Mon Sep 17 00:00:00 2001 From: Ethan Smith Date: Sat, 2 Dec 2017 13:45:23 -0800 Subject: [PATCH 1/3] Document empty tuple syntax --- docs/source/cheat_sheet.rst | 3 +++ docs/source/cheat_sheet_py3.rst | 3 +++ 2 files changed, 6 insertions(+) diff --git a/docs/source/cheat_sheet.rst b/docs/source/cheat_sheet.rst index a1cdb980df07..590820c943af 100644 --- a/docs/source/cheat_sheet.rst +++ b/docs/source/cheat_sheet.rst @@ -33,6 +33,9 @@ Built-in types x = [1] # type: List[int] x = set([6, 7]) # type: Set[int] + # Empty Tuple types are a bit special + x = () # type: Tuple[()] + # For mappings, we need the types of both keys and values. x = dict(field=2.0) # type: Dict[str, float] diff --git a/docs/source/cheat_sheet_py3.rst b/docs/source/cheat_sheet_py3.rst index 09eab13d4bf4..86280257a8b4 100644 --- a/docs/source/cheat_sheet_py3.rst +++ b/docs/source/cheat_sheet_py3.rst @@ -34,6 +34,9 @@ Built-in types x = [1] # type: List[int] x = {6, 7} # type: Set[int] + # Empty Tuple types are a bit special + x = () # type: Tuple[()] + # For mappings, we need the types of both keys and values. x = {'field': 2.0} # type: Dict[str, float] From 9a79cfadc0721dddcfa32ab4df4755346d0d87e8 Mon Sep 17 00:00:00 2001 From: Ethan Smith Date: Sun, 3 Dec 2017 23:16:41 -0800 Subject: [PATCH 2/3] Add Tuple and note about empty tuple --- docs/source/builtin_types.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/source/builtin_types.rst b/docs/source/builtin_types.rst index 4426df73868c..e6be2efdfb9b 100644 --- a/docs/source/builtin_types.rst +++ b/docs/source/builtin_types.rst @@ -13,6 +13,7 @@ Type Description ``bytes`` 8-bit string ``object`` an arbitrary object (``object`` is the common base class) ``List[str]`` list of ``str`` objects +``Tuple[int]`` a tuple of one int, ``Tuple[()]`` is the empty tuple ``Dict[str, int]`` dictionary from ``str`` keys to ``int`` values ``Iterable[int]`` iterable object containing ints ``Sequence[bool]`` sequence of booleans From 7db5f597cce951635f0d2cb2bade82d59167d695 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Mon, 4 Dec 2017 07:48:23 -0800 Subject: [PATCH 3/3] Tweak Tuple examples --- docs/source/builtin_types.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/source/builtin_types.rst b/docs/source/builtin_types.rst index e6be2efdfb9b..e41c5db6fbf5 100644 --- a/docs/source/builtin_types.rst +++ b/docs/source/builtin_types.rst @@ -13,7 +13,8 @@ Type Description ``bytes`` 8-bit string ``object`` an arbitrary object (``object`` is the common base class) ``List[str]`` list of ``str`` objects -``Tuple[int]`` a tuple of one int, ``Tuple[()]`` is the empty tuple +``Tuple[int, int]`` tuple of two ``int``s (``Tuple[()]`` is the empty tuple) +``Tuple[int, ...]`` tuple of an arbitrary number of ``int`` objects ``Dict[str, int]`` dictionary from ``str`` keys to ``int`` values ``Iterable[int]`` iterable object containing ints ``Sequence[bool]`` sequence of booleans