8000 Minor modernization and readability improvement to the tokenizer exam… · python/cpython@22a4849 · GitHub
[go: up one dir, main page]

Skip to content

Commit 22a4849

Browse files
Minor modernization and readability improvement to the tokenizer example (GH-19558) (GH-19661)
(cherry picked from commit bf1a812)
1 parent fc45cb4 commit 22a4849

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

Doc/library/re.rst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1617,10 +1617,14 @@ The text categories are specified with regular expressions. The technique is
16171617
to combine those into a single master regular expression and to loop over
16181618
successive matches::
16191619

1620< 7BBE code>-
import collections
1620+
from typing import NamedTuple
16211621
import re
16221622

1623-
Token = collections.namedtuple('Token', ['type', 'value', 'line', 'column'])
1623+
class Token(NamedTuple):
1624+
type: str
1625+
value: str
1626+
line: int
1627+
column: int
16241628

16251629
def tokenize(code):
16261630
keywords = {'IF', 'THEN', 'ENDIF', 'FOR', 'NEXT', 'GOSUB', 'RETURN'}

0 commit comments

Comments
 (0)
0