]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Minor modernization and readability improvement to the tokenizer example (GH-19558...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Wed, 22 Apr 2020 20:50:32 +0000 (13:50 -0700)
committerGitHub <noreply@github.com>
Wed, 22 Apr 2020 20:50:32 +0000 (13:50 -0700)
(cherry picked from commit bf1a81258c0ecc8b52b9dcc53321c066b3ed4a67)

Doc/library/re.rst

index 7c950bfd5b1fd521e5701a660be6dc64b8e69740..9abbd8ba73616eeceae8adb72abf884a34a33aae 100644 (file)
@@ -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'}