From fb4dc542ba4daeeeb1171a66aef8ce5263826091 Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Fri, 13 Mar 2009 10:02:52 +0100 Subject: [PATCH] use new-style classes everywhere to prevent unexpected obstacles in getting 2to3 clean --- Cython/Compiler/Annotate.py | 2 +- Cython/Compiler/Code.py | 2 +- Cython/Compiler/ControlFlow.py | 2 +- Cython/Compiler/Interpreter.py | 2 +- Cython/Compiler/Main.py | 8 +- Cython/Compiler/Nodes.py | 2 +- Cython/Compiler/ParseTreeTransforms.py | 2 +- Cython/Compiler/Scanning.py | 6 +- Cython/Compiler/Symtab.py | 6 +- .../Compiler/Tests/TestParseTreeTransforms.py | 2 +- Cython/Compiler/TypeSlots.py | 4 +- Cython/Mac/TS_Misc_Suite.py | 2 +- Cython/Plex/Actions.py | 2 +- Cython/Plex/DFA.py | 2 +- Cython/Plex/Lexicons.py | 4 +- Cython/Plex/Machines.py | 74 +------------------ Cython/Plex/Regexps.py | 2 +- Cython/Plex/Scanners.py | 2 +- Cython/Plex/Traditional.py | 2 +- Cython/Plex/Transitions.py | 2 +- 20 files changed, 31 insertions(+), 99 deletions(-) diff --git a/Cython/Compiler/Annotate.py b/Cython/Compiler/Annotate.py index 09b60251..dc330711 100644 --- a/Cython/Compiler/Annotate.py +++ b/Cython/Compiler/Annotate.py @@ -170,7 +170,7 @@ def escape(raw_string): return raw_string -class AnnotationItem: +class AnnotationItem(object): def __init__(self, style, text, tag="", size=0): self.style = style diff --git a/Cython/Compiler/Code.py b/Cython/Compiler/Code.py index cfc59bd8..aad42442 100644 --- a/Cython/Compiler/Code.py +++ b/Cython/Compiler/Code.py @@ -929,7 +929,7 @@ class CCodeWriter(object): self.putln("__Pyx_FinishRefcountContext();") -class PyrexCodeWriter: +class PyrexCodeWriter(object): # f file output file # level int indentation level diff --git a/Cython/Compiler/ControlFlow.py b/Cython/Compiler/ControlFlow.py index e433f7d0..80d32eb5 100644 --- a/Cython/Compiler/ControlFlow.py +++ b/Cython/Compiler/ControlFlow.py @@ -15,7 +15,7 @@ import bisect, sys _END_POS = ((unichr(sys.maxunicode)*10),()) -class ControlFlow: +class ControlFlow(object): def __init__(self, start_pos, incoming, parent): self.start_pos = start_pos diff --git a/Cython/Compiler/Interpreter.py b/Cython/Compiler/Interpreter.py index bd6e4bf5..eb7ea92c 100644 --- a/Cython/Compiler/Interpreter.py +++ b/Cython/Compiler/Interpreter.py @@ -12,7 +12,7 @@ from Visitor import BasicVisitor from Errors import CompileError -class EmptyScope: +class EmptyScope(object): def lookup(self, name): return None diff --git a/Cython/Compiler/Main.py b/Cython/Compiler/Main.py index ebdad275..6fb86764 100644 --- a/Cython/Compiler/Main.py +++ b/Cython/Compiler/Main.py @@ -34,7 +34,7 @@ def dumptree(t): print t.dump() return t -class CompilationData: +class CompilationData(object): # Bundles the information that is passed from transform to transform. # (For now, this is only) @@ -48,7 +48,7 @@ class CompilationData: # result CompilationResult pass -class Context: +class Context(object): # This class encapsulates the context needed for compiling # one or more Cython implementation files along with their # associated and imported declaration files. It includes @@ -556,7 +556,7 @@ class CompilationSource(object): self.full_module_name = full_module_name self.cwd = cwd -class CompilationOptions: +class CompilationOptions(object): """ Options to the Cython compiler: @@ -597,7 +597,7 @@ class CompilationOptions: self.obj_only = 0 -class CompilationResult: +class CompilationResult(object): """ Results from the Cython compiler: diff --git a/Cython/Compiler/Nodes.py b/Cython/Compiler/Nodes.py index 7610204c..eadfc5be 100644 --- a/Cython/Compiler/Nodes.py +++ b/Cython/Compiler/Nodes.py @@ -3727,7 +3727,7 @@ class SwitchStatNode(StatNode): if self.else_clause is not None: self.else_clause.annotate(code) -class LoopNode: +class LoopNode(object): def analyse_control_flow(self, env): env.start_branching(self.pos) diff --git a/Cython/Compiler/ParseTreeTransforms.py b/Cython/Compiler/ParseTreeTransforms.py index dc0560c1..3f92d738 100644 --- a/Cython/Compiler/ParseTreeTransforms.py +++ b/Cython/Compiler/ParseTreeTransforms.py @@ -27,7 +27,7 @@ class NameNodeCollector(TreeVisitor): self.name_nodes.append(node) -class SkipDeclarations: +class SkipDeclarations(object): """ Variable and function declarations can often have a deep tree structure, and yet most transformations don't need to descend to this depth. diff --git a/Cython/Compiler/Scanning.py b/Cython/Compiler/Scanning.py index 3b448fca..9ef47dc1 100644 --- a/Cython/Compiler/Scanning.py +++ b/Cython/Compiler/Scanning.py @@ -154,7 +154,7 @@ reserved_words = [ "cimport", "by", "with", "cpdef", "DEF", "IF", "ELIF", "ELSE" ] -class Method: +class Method(object): def __init__(self, name): self.name = name @@ -176,7 +176,7 @@ resword_dict = build_resword_dict() #------------------------------------------------------------------ -class CompileTimeScope: +class CompileTimeScope(object): def __init__(self, outer = None): self.entries = {} @@ -220,7 +220,7 @@ def initial_compile_time_env(): #------------------------------------------------------------------ -class SourceDescriptor: +class SourceDescriptor(object): """ A SourceDescriptor should be considered immutable. """ diff --git a/Cython/Compiler/Symtab.py b/Cython/Compiler/Symtab.py index ef56b4ed..58b57c85 100644 --- a/Cython/Compiler/Symtab.py +++ b/Cython/Compiler/Symtab.py @@ -23,7 +23,7 @@ except NameError: possible_identifier = re.compile(ur"(?![0-9])\w+$", re.U).match nice_identifier = re.compile('^[a-zA-Z0-0_]+$').match -class BufferAux: +class BufferAux(object): writable_needed = False def __init__(self, buffer_info_var, stridevars, shapevars, @@ -36,7 +36,7 @@ class BufferAux: def __repr__(self): return "" % self.__dict__ -class Entry: +class Entry(object): # A symbol table entry in a Scope or ModuleNamespace. # # name string Python name of entity @@ -158,7 +158,7 @@ class Entry: error(pos, "'%s' does not match previous declaration" % self.name) error(self.pos, "Previous declaration is here") -class Scope: +class Scope(object): # name string Unqualified name # outer_scope Scope or None Enclosing scope # entries {string : Entry} Python name to entry, non-types diff --git a/Cython/Compiler/Tests/TestParseTreeTransforms.py b/Cython/Compiler/Tests/TestParseTreeTransforms.py index 518eda14..a56f81c5 100644 --- a/Cython/Compiler/Tests/TestParseTreeTransforms.py +++ b/Cython/Compiler/Tests/TestParseTreeTransforms.py @@ -85,7 +85,7 @@ class TestNormalizeTree(TransformTest): t = self.run_pipeline([NormalizeTree(None)], u"pass") self.assert_(len(t.stats) == 0) -class TestWithTransform:#(TransformTest): Disabled +class TestWithTransform(object): # (TransformTest): # Disabled! def test_simplified(self): t = self.run_pipeline([WithTransform(None)], u""" diff --git a/Cython/Compiler/TypeSlots.py b/Cython/Compiler/TypeSlots.py index cf0bf1fd..bc70abcc 100644 --- a/Cython/Compiler/TypeSlots.py +++ b/Cython/Compiler/TypeSlots.py @@ -8,7 +8,7 @@ import PyrexTypes import StringEncoding import sys -class Signature: +class Signature(object): # Method slot signature descriptor. # # has_dummy_arg boolean @@ -119,7 +119,7 @@ class Signature: return None -class SlotDescriptor: +class SlotDescriptor(object): # Abstract base class for type slot descriptors. # # slot_name string Member name of the slot in the type object diff --git a/Cython/Mac/TS_Misc_Suite.py b/Cython/Mac/TS_Misc_Suite.py index e75a1c8d..bbfc0e3f 100644 --- a/Cython/Mac/TS_Misc_Suite.py +++ b/Cython/Mac/TS_Misc_Suite.py @@ -10,7 +10,7 @@ import MacOS _code = 'misc' -class TS_Misc_Suite: +class TS_Misc_Suite(object): def DoScript(self, _object, _attributes={}, **_arguments): """DoScript: Execute an MPW command, any command that could be executed from the command line can be sent as a script. diff --git a/Cython/Plex/Actions.py b/Cython/Plex/Actions.py index 23253a90..9da4e340 100644 --- a/Cython/Plex/Actions.py +++ b/Cython/Plex/Actions.py @@ -6,7 +6,7 @@ # #======================================================================= -class Action: +class Action(object): def same_as(self, other): return self is other diff --git a/Cython/Plex/DFA.py b/Cython/Plex/DFA.py index 81186364..a24d3cea 100644 --- a/Cython/Plex/DFA.py +++ b/Cython/Plex/DFA.py @@ -83,7 +83,7 @@ def add_to_epsilon_closure(state_set, state): for state2 in state_set_2.keys(): add_to_epsilon_closure(state_set, state2) -class StateMap: +class StateMap(object): """ Helper class used by nfa_to_dfa() to map back and forth between sets of states from the old machine and states of the new machine. diff --git a/Cython/Plex/Lexicons.py b/Cython/Plex/Lexicons.py index 2dbfaf06..905c6c50 100644 --- a/Cython/Plex/Lexicons.py +++ b/Cython/Plex/Lexicons.py @@ -18,7 +18,7 @@ import Regexps DUMP_NFA = 1 DUMP_DFA = 2 -class State: +class State(object): """ This class is used as part of a Plex.Lexicon specification to introduce a user-defined state. @@ -35,7 +35,7 @@ class State: self.name = name self.tokens = tokens -class Lexicon: +class Lexicon(object): """ Lexicon(specification) builds a lexical analyser from the given |specification|. The specification consists of a list of diff --git a/Cython/Plex/Machines.py b/Cython/Plex/Machines.py index 4d788edb..a9c69c63 100644 --- a/Cython/Plex/Machines.py +++ b/Cython/Plex/Machines.py @@ -15,7 +15,7 @@ from Transitions import TransitionMap LOWEST_PRIORITY = -sys.maxint -class Machine: +class Machine(object): """A collection of Nodes representing an NFA or DFA.""" states = None # [Node] next_state_number = 1 @@ -59,7 +59,7 @@ class Machine: for s in self.states: s.dump(file) -class Node: +class Node(object): """A state of an NFA or DFA.""" transitions = None # TransitionMap action = None # Action @@ -101,13 +101,6 @@ class Node: def get_action_priority(self): return self.action_priority -# def merge_actions(self, other_state): -# """Merge actions of other state into this state according -# to their priorities.""" -# action = other_state.get_action() -# priority = other_state.get_action_priority() -# self.set_action(action, priority) - def is_accepting(self): return self.action is not None @@ -128,7 +121,7 @@ class Node: file.write(" %s [priority %d]\n" % (action, priority)) -class FastMachine: +class FastMachine(object): """ FastMachine is a deterministic machine represented in a way that allows fast scanning. @@ -264,64 +257,3 @@ class FastMachine: return repr(c1) else: return "%s..%s" % (repr(c1), repr(c2)) -## -## (Superseded by Machines.FastMachine) -## -## class StateTableMachine: -## """ -## StateTableMachine is an alternative representation of a Machine -## that can be run more efficiently. -## """ -## initial_states = None # {state_name:state_index} -## states = None # [([state] indexed by char code, Action)] - -## special_map = {'bol':256, 'eol':257, 'eof':258} - -## def __init__(self, m): -## """ -## Initialise StateTableMachine from Machine |m|. -## """ -## initial_states = self.initial_states = {} -## states = self.states = [None] -## old_to_new = {} -## i = 1 -## for old_state in m.states: -## new_state = ([0] * 259, old_state.get_action()) -## states.append(new_state) -## old_to_new[old_state] = i # new_state -## i = i + 1 -## for name, old_state in m.initial_states.items(): -## initial_states[name] = old_to_new[old_state] -## for old_state in m.states: -## new_state_index = old_to_new[old_state] -## new_table = states[new_state_index][0] -## transitions = old_state.transitions -## for c, old_targets in transitions.items(): -## if old_targets: -## old_target = old_targets[0] -## new_target_index = old_to_new[old_target] -## if len(c) == 1: -## a = ord(c) -## else: -## a = self.special_map[c] -## new_table[a] = states[new_target_index] - -## def dump(self, f): -## f.write("Plex.StateTableMachine:\n") -## f.write(" Initial states:\n") -## for name, index in self.initial_states.items(): -## f.write(" %s: State %d\n" % ( -## repr(name), id(self.states[index]))) -## for i in xrange(1, len(self.states)): -## table, action = self.states[i] -## f.write(" State %d:" % i) -## if action: -## f.write("%s" % action) -## f.write("\n") -## f.write(" %s\n" % map(id,table)) - - - - - - diff --git a/Cython/Plex/Regexps.py b/Cython/Plex/Regexps.py index 09619240..90dbe934 100644 --- a/Cython/Plex/Regexps.py +++ b/Cython/Plex/Regexps.py @@ -101,7 +101,7 @@ def CodeRange(code1, code2): # Abstract classes # -class RE: +class RE(object): """RE is the base class for regular expression constructors. The following operators are defined on REs: diff --git a/Cython/Plex/Scanners.py b/Cython/Plex/Scanners.py index c6d511ed..d05f909c 100644 --- a/Cython/Plex/Scanners.py +++ b/Cython/Plex/Scanners.py @@ -12,7 +12,7 @@ from Regexps import BOL, EOL, EOF import cython -class Scanner: +class Scanner(object): """ A Scanner is used to read tokens from a stream of characters using the token set specified by a Plex.Lexicon. diff --git a/Cython/Plex/Traditional.py b/Cython/Plex/Traditional.py index 1f6d6726..5d8f9130 100644 --- a/Cython/Plex/Traditional.py +++ b/Cython/Plex/Traditional.py @@ -19,7 +19,7 @@ def re(s): """ return REParser(s).parse_re() -class REParser: +class REParser(object): def __init__(self, s): self.s = s diff --git a/Cython/Plex/Transitions.py b/Cython/Plex/Transitions.py index 84eda51f..4119e71b 100644 --- a/Cython/Plex/Transitions.py +++ b/Cython/Plex/Transitions.py @@ -10,7 +10,7 @@ import string from sys import maxint from types import TupleType -class TransitionMap: +class TransitionMap(object): """ A TransitionMap maps an input event to a set of states. An input event is one of: a range of character codes, -- 2.26.2