summaryrefslogtreecommitdiffstats
path: root/Doc/library
diff options
context:
space:
mode:
authorCollin Winter <collinw@gmail.com>2007-08-28 06:10:19 (GMT)
committerCollin Winter <collinw@gmail.com>2007-08-28 06:10:19 (GMT)
commit1b1498b42e00a5bbb29f67e49f5993a47fb9cceb (patch)
tree45f5c6c8fb1834a67c4b6628eef86b5c47b1f0d9 /Doc/library
parentd1d9a890eb45951b4bc6f5b9d497bd62f16ed361 (diff)
downloadcpython-1b1498b42e00a5bbb29f67e49f5993a47fb9cceb.zip
cpython-1b1498b42e00a5bbb29f67e49f5993a47fb9cceb.tar.gz
cpython-1b1498b42e00a5bbb29f67e49f5993a47fb9cceb.tar.bz2
Idiom adjustment in the docs for the parser module.
Diffstat (limited to 'Doc/library')
-rw-r--r--Doc/library/parser.rst14
1 files changed, 6 insertions, 8 deletions
diff --git a/Doc/library/parser.rst b/Doc/library/parser.rst
index b767561..e361a26 100644
--- a/Doc/library/parser.rst
+++ b/Doc/library/parser.rst
@@ -474,19 +474,17 @@ representation to be ``['variable_name']``. A simple recursive function can
implement the pattern matching, returning a Boolean and a dictionary of variable
name to value mappings. (See file :file:`example.py`.) ::
- from types import ListType, TupleType
-
def match(pattern, data, vars=None):
if vars is None:
vars = {}
- if type(pattern) is ListType:
+ if isinstance(pattern, list):
vars[pattern[0]] = data
- return 1, vars
- if type(pattern) is not TupleType:
+ return True, vars
+ if not instance(pattern, tuple):
return (pattern == data), vars
if len(data) != len(pattern):
- return 0, vars
- for pattern, data in map(None, pattern, data):
+ return False, vars
+ for pattern, data in zip(pattern, data):
same, vars = match(pattern, data, vars)
if not same:
break
@@ -528,7 +526,7 @@ docstring from the parse tree created previously is easy::
>>> found, vars = match(DOCSTRING_STMT_PATTERN, tup[1])
>>> found
- 1
+ True
>>> vars
{'docstring': '"""Some documentation.\n"""'}