from DebugFlags import debug_disposal_code, debug_temp_alloc, \
debug_coercion
+try:
+ from __builtin__ import basestring
+except ImportError:
+ basestring = str # Python 3
+
class NotConstant(object):
def __repr__(self):
return "<NOT CONSTANT>"
return "<error>"
formal_args = func_type.args
arg_list_code = []
- args = zip(formal_args, self.args)
+ args = list(zip(formal_args, self.args))
max_nargs = len(func_type.args)
expected_nargs = max_nargs - func_type.optional_arg_count
actual_nargs = len(self.args)
self.opt_arg_struct,
Naming.pyrex_prefix + "n",
len(self.args) - expected_nargs))
- args = zip(func_type.args, self.args)
+ args = list(zip(func_type.args, self.args))
for formal_arg, actual_arg in args[expected_nargs:actual_nargs]:
code.putln("%s.%s = %s;" % (
self.opt_arg_struct,
# Pyrex - Parse tree nodes
#
-import sys, os, time, copy
+import cython
+from cython import set
+cython.declare(sys=object, os=object, time=object, copy=object,
+ Builtin=object, error=object, warning=object, Naming=object, PyrexTypes=object,
+ py_object_type=object, ModuleScope=object, LocalScope=object, ClosureScope=object, \
+ StructOrUnionScope=object, PyClassScope=object, CClassScope=object,
+ CppClassScope=object, UtilityCode=object, EncodedString=object,
+ absolute_path_length=cython.Py_ssize_t)
-try:
- set
-except NameError:
- # Python 2.3
- from sets import Set as set
+import sys, os, time, copy
-import Code
import Builtin
from Errors import error, warning, InternalError
import Naming
return repr(x)
- attrs = [(key, value) for key, value in self.__dict__.iteritems() if key not in filter_out]
+ attrs = [(key, value) for key, value in self.__dict__.items() if key not in filter_out]
if len(attrs) == 0:
return "<%s (0x%x)>" % (self.__class__.__name__, id(self))
else:
if sys.version_info[0] < 3:
# Py 2.x enforces byte strings as keyword arguments ...
options = dict([ (name.encode('ASCII'), value)
- for name, value in options.iteritems() ])
+ for name, value in options.items() ])
self.type = PyrexTypes.BufferType(base_type, **options)
except ImportError:
from functools import reduce
+try:
+ from __builtin__ import basestring
+except ImportError:
+ basestring = str # Python 3
+
class FakePythonEnv(object):
"A fake environment for creating type test nodes etc."
nogil = False
def extract_in_string_conditions(self, string_literal):
if isinstance(string_literal, ExprNodes.UnicodeNode):
- charvals = map(ord, set(string_literal.value))
+ charvals = list(map(ord, set(string_literal.value)))
charvals.sort()
return [ ExprNodes.IntNode(string_literal.pos, value=str(charval),
constant_result=charval)
# check if all children are constant
children = self.visitchildren(node)
- for child_result in children.itervalues():
+ for child_result in children.values():
if type(child_result) is list:
for child in child_result:
if getattr(child, 'constant_result', not_a_constant) is not_a_constant:
+
+import cython
+from cython import set
+cython.declare(copy=object, ModuleNode=object, TreeFragment=object, TemplateTransform=object,
+ EncodedString=object, error=object, PyrexTypes=object, Naming=object)
+
from Cython.Compiler.Visitor import VisitorTransform, TreeVisitor
from Cython.Compiler.Visitor import CythonTransform, EnvTransform, ScopeTrackingTransform
from Cython.Compiler.ModuleNode import ModuleNode
from Cython.Compiler.TreeFragment import TreeFragment, TemplateTransform
from Cython.Compiler.StringEncoding import EncodedString
from Cython.Compiler.Errors import error, CompileError
-try:
- set
-except NameError:
- from sets import Set as set
+from Cython.Compiler import PyrexTypes, Naming
+
import copy
special_methods = set(['declare', 'union', 'struct', 'typedef', 'sizeof',
'cast', 'pointer', 'compiled', 'NULL']
- + unop_method_nodes.keys())
+ + list(unop_method_nodes.keys()))
def __init__(self, context, compilation_directive_defaults):
super(InterpretCompilerDirectives, self).__init__(context)
self.compilation_directive_defaults = {}
- for key, value in compilation_directive_defaults.iteritems():
+ for key, value in compilation_directive_defaults.items():
self.compilation_directive_defaults[unicode(key)] = value
self.cython_module_names = set()
self.directive_names = {}
# Set up processing and handle the cython: comments.
def visit_ModuleNode(self, node):
- for key, value in node.directive_comments.iteritems():
+ for key, value in node.directive_comments.items():
if not self.check_directive_scope(node.pos, key, 'module'):
self.wrong_scope_error(node.pos, key, 'module')
del node.directive_comments[key]