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

Skip to content

Commit 995285e

Browse files
committed
Moved all the imports to the top.
Use the methods on the AST object instead of module-level functions; these have been implemented for a couple of versions now, and are already used in the module documentation in preference to the functions.
1 parent d81b1b0 commit 995285e

1 file changed

Lines changed: 5 additions & 9 deletions

File tree

Demo/parser/example.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,14 @@
55
discussion of the operation of this code.
66
"""
77

8+
import os
9+
import parser
810
import symbol
911
import token
1012
import types
1113

14+
from types import ListType, TupleType
15+
1216

1317
def get_docs(fileName):
1418
"""Retrieve information from the parse tree of a source file.
@@ -17,12 +21,9 @@ def get_docs(fileName):
1721
Name of the file to read Python source code from.
1822
"""
1923
source = open(fileName).read()
20-
import os
2124
basename = os.path.basename(os.path.splitext(fileName)[0])
22-
import parser
2325
ast = parser.suite(source)
24-
tup = parser.ast2tuple(ast)
25-
return ModuleInfo(tup, basename)
26+
return ModuleInfo(ast.totuple(), basename)
2627

2728

2829
class SuiteInfoBase:
@@ -112,8 +113,6 @@ def __init__(self, tree = None, name = "<string>"):
112113
self._docstring = vars["docstring"]
113114

114115

115-
from types import ListType, TupleType
116-
117116
def match(pattern, data, vars=None):
118117
"""Match `data' to `pattern', with variable extraction.
119118
@@ -189,6 +188,3 @@ def match(pattern, data, vars=None):
189188
)))))))))))))))),
190189
(token.NEWLINE, '')
191190
))
192-
193-
#
194-
# end of file

0 commit comments

Comments
 (0)