Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1b1498b

Browse files
committed
Idiom adjustment in the docs for the parser module.
1 parent d1d9a89 commit 1b1498b

1 file changed

Lines changed: 6 additions & 8 deletions

File tree

Doc/library/parser.rst

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -474,19 +474,17 @@ representation to be ``['variable_name']``. A simple recursive function can
474474
implement the pattern matching, returning a Boolean and a dictionary of variable
475475
name to value mappings. (See file :file:`example.py`.) ::
476476

477-
from types import ListType, TupleType
478-
479477
def match(pattern, data, vars=None):
480478
if vars is None:
481479
vars = {}
482-
if type(pattern) is ListType:
480+
if isinstance(pattern, list):
483481
vars[pattern[0]] = data
484-
return 1, vars
485-
if type(pattern) is not TupleType:
482+
return True, vars
483+
if not instance(pattern, tuple):
486484
return (pattern == data), vars
487485
if len(data) != len(pattern):
488-
return 0, vars
489-
for pattern, data in map(None, pattern, data):
486+
return False, vars
487+
for pattern, data in zip(pattern, data):
490488
same, vars = match(pattern, data, vars)
491489
if not same:
492490
break
@@ -528,7 +526,7 @@ docstring from the parse tree created previously is easy::
528526

529527
>>> found, vars = match(DOCSTRING_STMT_PATTERN, tup[1])
530528
>>> found
531-
1
529+
True
532530
>>> vars
533531
{'docstring': '"""Some documentation.\n"""'}
534532

0 commit comments

Comments
 (0)