diff options
author | Georg Brandl <georg@python.org> | 2008-12-15 08:58:59 (GMT) |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2008-12-15 08:58:59 (GMT) |
commit | 2d2fe572a4605d3c25055717c1033589e2889e65 (patch) | |
tree | c5d67af0ba51c48f36bf7117539f26ea04b496fe /Lib | |
parent | cbc1ed5e2811d2ef7dbf243a1adbcf1c9bf6cba1 (diff) | |
download | cpython-2d2fe572a4605d3c25055717c1033589e2889e65.zip cpython-2d2fe572a4605d3c25055717c1033589e2889e65.tar.gz cpython-2d2fe572a4605d3c25055717c1033589e2889e65.tar.bz2 |
#4578: fix has_key() usage in compiler package.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/compiler/misc.py | 4 | ||||
-rw-r--r-- | Lib/compiler/pyassem.py | 6 | ||||
-rw-r--r-- | Lib/compiler/symbols.py | 18 | ||||
-rw-r--r-- | Lib/compiler/transformer.py | 4 | ||||
-rw-r--r-- | Lib/compiler/visitor.py | 2 |
5 files changed, 16 insertions, 18 deletions
diff --git a/Lib/compiler/misc.py b/Lib/compiler/misc.py index 8d91770..588c7fb 100644 --- a/Lib/compiler/misc.py +++ b/Lib/compiler/misc.py @@ -14,13 +14,13 @@ class Set: def __len__(self): return len(self.elts) def __contains__(self, elt): - return self.elts.has_key(elt) + return elt in self.elts def add(self, elt): self.elts[elt] = elt def elements(self): return self.elts.keys() def has_elt(self, elt): - return self.elts.has_key(elt) + return elt in self.elts def remove(self, elt): del self.elts[elt] def copy(self): diff --git a/Lib/compiler/pyassem.py b/Lib/compiler/pyassem.py index 893fa64..6efec28 100644 --- a/Lib/compiler/pyassem.py +++ b/Lib/compiler/pyassem.py @@ -210,7 +210,7 @@ def dfs_postorder(b, seen): order = [] seen[b] = b for c in b.get_children(): - if seen.has_key(c): + if c in seen: continue order = order + dfs_postorder(c, seen) order.append(b) @@ -406,7 +406,7 @@ class PyFlowGraph(FlowGraph): seen = {} def max_depth(b, d): - if seen.has_key(b): + if b in seen: return d seen[b] = 1 d = d + depth[b] @@ -482,7 +482,7 @@ class PyFlowGraph(FlowGraph): for name in self.cellvars: cells[name] = 1 self.cellvars = [name for name in self.varnames - if cells.has_key(name)] + if name in cells] for name in self.cellvars: del cells[name] self.cellvars = self.cellvars + cells.keys() diff --git a/Lib/compiler/symbols.py b/Lib/compiler/symbols.py index 8f62980..0e660ae 100644 --- a/Lib/compiler/symbols.py +++ b/Lib/compiler/symbols.py @@ -49,9 +49,9 @@ class Scope: def add_global(self, name): name = self.mangle(name) - if self.uses.has_key(name) or self.defs.has_key(name): + if name in self.uses or name in self.defs: pass # XXX warn about global following def/use - if self.params.has_key(name): + if name in self.params: raise SyntaxError, "%s in %s is global and parameter" % \ (name, self.name) self.globals[name] = 1 @@ -88,14 +88,13 @@ class Scope: The scope of a name could be LOCAL, GLOBAL, FREE, or CELL. """ - if self.globals.has_key(name): + if name in self.globals: return SC_GLOBAL - if self.cells.has_key(name): + if name in self.cells: return SC_CELL - if self.defs.has_key(name): + if name in self.defs: return SC_LOCAL - if self.nested and (self.frees.has_key(name) or - self.uses.has_key(name)): + if self.nested and (name in self.frees or name in self.uses): return SC_FREE if self.nested: return SC_UNKNOWN @@ -108,8 +107,7 @@ class Scope: free = {} free.update(self.frees) for name in self.uses.keys(): - if not (self.defs.has_key(name) or - self.globals.has_key(name)): + if name not in self.defs and name not in self.globals: free[name] = 1 return free.keys() @@ -134,7 +132,7 @@ class Scope: free. """ self.globals[name] = 1 - if self.frees.has_key(name): + if name in self.frees: del self.frees[name] for child in self.children: if child.check_name(name) == SC_FREE: diff --git a/Lib/compiler/transformer.py b/Lib/compiler/transformer.py index eccade3..f5fe582 100644 --- a/Lib/compiler/transformer.py +++ b/Lib/compiler/transformer.py @@ -81,7 +81,7 @@ def extractLineNo(ast): def Node(*args): kind = args[0] - if nodes.has_key(kind): + if kind in nodes: try: return nodes[kind](*args[1:]) except TypeError: @@ -120,7 +120,7 @@ class Transformer: def transform(self, tree): """Transform an AST into a modified parse tree.""" if not (isinstance(tree, tuple) or isinstance(tree, list)): - tree = parser.ast2tuple(tree, line_info=1) + tree = parser.st2tuple(tree, line_info=1) return self.compile_node(tree) def parsesuite(self, text): diff --git a/Lib/compiler/visitor.py b/Lib/compiler/visitor.py index 9e39d36..f10f560 100644 --- a/Lib/compiler/visitor.py +++ b/Lib/compiler/visitor.py @@ -84,7 +84,7 @@ class ExampleASTVisitor(ASTVisitor): meth(node, *args) elif self.VERBOSE > 0: klass = node.__class__ - if not self.examples.has_key(klass): + if klass not in self.examples: self.examples[klass] = klass print print self.visitor |