]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Minor modernization and readability improvement to the tokenizer example (GH-19558)
authorRaymond Hettinger <rhettinger@users.noreply.github.com>
Fri, 17 Apr 2020 02:54:13 +0000 (19:54 -0700)
committerGitHub <noreply@github.com>
Fri, 17 Apr 2020 02:54:13 +0000 (19:54 -0700)
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'}