summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2020-04-22 20:50:32 (GMT)
committerGitHub <noreply@github.com>2020-04-22 20:50:32 (GMT)
commit22a4849cd8356de0f6ed8586ed8aac7ad1f3df6c (patch)
treedbcdd3e7825a17432775597778ed77a7efb1b418 /Doc
parentfc45cb4400409572f05c8b54f2c6f06cbefb1b4e (diff)
downloadcpython-22a4849cd8356de0f6ed8586ed8aac7ad1f3df6c.zip
cpython-22a4849cd8356de0f6ed8586ed8aac7ad1f3df6c.tar.gz
cpython-22a4849cd8356de0f6ed8586ed8aac7ad1f3df6c.tar.bz2
Minor modernization and readability improvement to the tokenizer example (GH-19558) (GH-19661)
(cherry picked from commit bf1a81258c0ecc8b52b9dcc53321c066b3ed4a67)
Diffstat (limited to 'Doc')
-rw-r--r--Doc/library/re.rst8
1 files changed, 6 insertions, 2 deletions
diff --git a/Doc/library/re.rst b/Doc/library/re.rst
index 7c950bf..9abbd8b 100644
--- a/Doc/library/re.rst
+++ b/Doc/library/re.rst
@@ -1617,10 +1617,14 @@ The text categories are specified with regular expressions. The technique is
to combine those into a single master regular expression and to loop over
successive matches::
- import collections
+ from typing import NamedTuple
import re
- Token = collections.namedtuple('Token', ['type', 'value', 'line', 'column'])
+ class Token(NamedTuple):
+ type: str
+ value: str
+ line: int
+ column: int
def tokenize(code):
keywords = {'IF', 'THEN', 'ENDIF', 'FOR', 'NEXT', 'GOSUB', 'RETURN'}