Commit a8af26e0 authored by Stefan Behnel's avatar Stefan Behnel

Merge branch '0.24.x'

parents 9ef17d2e 642b09e7
......@@ -32,7 +32,7 @@ class DeclarationWriter(TreeVisitor):
indent_string = u" "
def __init__(self, result = None):
def __init__(self, result=None):
super(DeclarationWriter, self).__init__()
if result is None:
result = LinesResult()
......@@ -51,7 +51,7 @@ class DeclarationWriter(TreeVisitor):
def dedent(self):
self.numindents -= 1
def startline(self, s = u""):
def startline(self, s=u""):
self.result.put(self.indent_string * self.numindents + s)
def put(self, s):
......@@ -60,7 +60,7 @@ class DeclarationWriter(TreeVisitor):
def putline(self, s):
self.result.putline(self.indent_string * self.numindents + s)
def endline(self, s = u""):
def endline(self, s=u""):
self.result.putline(s)
def line(self, s):
......
......@@ -70,7 +70,7 @@ class EmbedSignature(CythonTransform):
except Exception:
try:
return self._fmt_expr_node(default_val)
except AttributeError as e:
except AttributeError:
return '<???>'
def _fmt_arg(self, arg):
......
......@@ -40,7 +40,7 @@ try:
except ImportError:
from builtins import str as basestring
KEYWORDS_MUST_BE_BYTES = sys.version_info < (2,7)
KEYWORDS_MUST_BE_BYTES = sys.version_info < (2, 7)
non_portable_builtins_map = {
......@@ -481,7 +481,7 @@ class UtilityCode(UtilityCodeBase):
is_specialised1, impl = self.inject_string_constants(impl, output)
is_specialised2, impl = self.inject_unbound_methods(impl, output)
writer = output['utility_code_def']
writer.putln("/* %s */" % self.name);
writer.putln("/* %s */" % self.name)
if not (is_specialised1 or is_specialised2):
# no module specific adaptations => can be reused
writer.put_or_include(impl, '%s_impl' % self.name)
......@@ -849,7 +849,7 @@ class StringConst(object):
def add_py_version(self, version):
if not version:
self.py_versions = [2,3]
self.py_versions = [2, 3]
elif version not in self.py_versions:
self.py_versions.append(version)
......@@ -1280,8 +1280,8 @@ class GlobalState(object):
self.generate_object_constant_decls()
def generate_object_constant_decls(self):
consts = [ (len(c.cname), c.cname, c)
for c in self.py_constants ]
consts = [(len(c.cname), c.cname, c)
for c in self.py_constants]
consts.sort()
decls_writer = self.parts['decls']
for _, cname, c in consts:
......@@ -1345,8 +1345,7 @@ class GlobalState(object):
py_strings.sort()
w = self.parts['pystring_table']
w.putln("")
w.putln("static __Pyx_StringTabEntry %s[] = {" %
Naming.stringtab_cname)
w.putln("static __Pyx_StringTabEntry %s[] = {" % Naming.stringtab_cname)
for c_cname, _, py_string in py_strings:
if not py_string.is_str or not py_string.encoding or \
py_string.encoding in ('ASCII', 'USASCII', 'US-ASCII',
......@@ -1359,8 +1358,7 @@ class GlobalState(object):
"static PyObject *%s;" % py_string.cname)
if py_string.py3str_cstring:
w.putln("#if PY_MAJOR_VERSION >= 3")
w.putln(
"{&%s, %s, sizeof(%s), %s, %d, %d, %d}," % (
w.putln("{&%s, %s, sizeof(%s), %s, %d, %d, %d}," % (
py_string.cname,
py_string.py3str_cstring.cname,
py_string.py3str_cstring.cname,
......@@ -1368,8 +1366,7 @@ class GlobalState(object):
py_string.intern
))
w.putln("#else")
w.putln(
"{&%s, %s, sizeof(%s), %s, %d, %d, %d}," % (
w.putln("{&%s, %s, sizeof(%s), %s, %d, %d, %d}," % (
py_string.cname,
c_cname,
c_cname,
......
This diff is collapsed.
This diff is collapsed.
......@@ -263,6 +263,7 @@ directive_scopes = { # defaults to available everywhere
'language_level': ('module',),
}
def parse_directive_value(name, value, relaxed_bool=False):
"""
Parses value as an option value for the given name and returns
......@@ -292,16 +293,21 @@ def parse_directive_value(name, value, relaxed_bool=False):
ValueError: c_string_type directive must be one of ('bytes', 'bytearray', 'str', 'unicode'), got 'unnicode'
"""
type = directive_types.get(name)
if not type: return None
if not type:
return None
orig_value = value
if type is bool:
value = str(value)
if value == 'True': return True
if value == 'False': return False
if value == 'True':
return True
if value == 'False':
return False
if relaxed_bool:
value = value.lower()
if value in ("true", "yes"): return True
elif value in ("false", "no"): return False
if value in ("true", "yes"):
return True
elif value in ("false", "no"):
return False
raise ValueError("%s directive must be set to True or False, got '%s'" % (
name, orig_value))
elif type is int:
......@@ -317,6 +323,7 @@ def parse_directive_value(name, value, relaxed_bool=False):
else:
assert False
def parse_directive_list(s, relaxed_bool=False, ignore_unknown=False,
current_settings=None):
"""
......@@ -352,9 +359,11 @@ def parse_directive_list(s, relaxed_bool=False, ignore_unknown=False,
result = current_settings
for item in s.split(','):
item = item.strip()
if not item: continue
if not '=' in item: raise ValueError('Expected "=" in option "%s"' % item)
name, value = [ s.strip() for s in item.strip().split('=', 1) ]
if not item:
continue
if not '=' in item:
raise ValueError('Expected "=" in option "%s"' % item)
name, value = [s.strip() for s in item.strip().split('=', 1)]
if name not in directive_defaults:
found = False
if name.endswith('.all'):
......
......@@ -68,7 +68,7 @@ class Method(object):
class CompileTimeScope(object):
def __init__(self, outer = None):
def __init__(self, outer=None):
self.entries = {}
self.outer = outer
......@@ -97,8 +97,7 @@ class CompileTimeScope(object):
def initial_compile_time_env():
benv = CompileTimeScope()
names = ('UNAME_SYSNAME', 'UNAME_NODENAME', 'UNAME_RELEASE',
'UNAME_VERSION', 'UNAME_MACHINE')
names = ('UNAME_SYSNAME', 'UNAME_NODENAME', 'UNAME_RELEASE', 'UNAME_VERSION', 'UNAME_MACHINE')
for name, value in zip(names, platform.uname()):
benv.declare(name, value)
try:
......@@ -272,8 +271,8 @@ class StringSourceDescriptor(SourceDescriptor):
if not encoding:
return self.codelines
else:
return [ line.encode(encoding, error_handling).decode(encoding)
for line in self.codelines ]
return [line.encode(encoding, error_handling).decode(encoding)
for line in self.codelines]
def get_description(self):
return self.name
......@@ -487,7 +486,7 @@ class PyrexScanner(Scanner):
else:
self.expected(what, message)
def expected(self, what, message = None):
def expected(self, what, message=None):
if message:
self.error(message)
else:
......
......@@ -17,8 +17,7 @@ class NonManglingModuleScope(Symtab.ModuleScope):
def add_imported_entry(self, name, entry, pos):
entry.used = True
return super(NonManglingModuleScope, self).add_imported_entry(
name, entry, pos)
return super(NonManglingModuleScope, self).add_imported_entry(name, entry, pos)
def mangle(self, prefix, name=None):
if name:
......@@ -137,26 +136,22 @@ class CythonUtilityCode(Code.UtilityCodeBase):
pipeline = Pipeline.insert_into_pipeline(pipeline, transform,
before=before)
if self.from_scope:
def scope_transform(module_node):
module_node.scope.merge_in(self.from_scope)
def merge_scope(scope):
def merge_scope_transform(module_node):
module_node.scope.merge_in(scope)
return module_node
return merge_scope_transform
transform = ParseTreeTransforms.AnalyseDeclarationsTransform
pipeline = Pipeline.insert_into_pipeline(pipeline, scope_transform,
before=transform)
if self.from_scope:
pipeline = Pipeline.insert_into_pipeline(
pipeline, merge_scope(self.from_scope),
before=ParseTreeTransforms.AnalyseDeclarationsTransform)
for dep in self.requires:
if (isinstance(dep, CythonUtilityCode)
and hasattr(dep, 'tree')
and not cython_scope):
def scope_transform(module_node):
module_node.scope.merge_in(dep.tree.scope)
return module_node
transform = ParseTreeTransforms.AnalyseDeclarationsTransform
pipeline = Pipeline.insert_into_pipeline(pipeline, scope_transform,
before=transform)
if isinstance(dep, CythonUtilityCode) and hasattr(dep, 'tree') and not cython_scope:
pipeline = Pipeline.insert_into_pipeline(
pipeline, merge_scope(dep.tree.scope),
before=ParseTreeTransforms.AnalyseDeclarationsTransform)
if self.outer_module_scope:
# inject outer module between utility code module and builtin module
......@@ -164,9 +159,9 @@ class CythonUtilityCode(Code.UtilityCodeBase):
module_node.scope.outer_scope = self.outer_module_scope
return module_node
transform = ParseTreeTransforms.AnalyseDeclarationsTransform
pipeline = Pipeline.insert_into_pipeline(pipeline, scope_transform,
before=transform)
pipeline = Pipeline.insert_into_pipeline(
pipeline, scope_transform,
before=ParseTreeTransforms.AnalyseDeclarationsTransform)
(err, tree) = Pipeline.run_pipeline(pipeline, tree, printtree=False)
assert not err, err
......@@ -199,13 +194,12 @@ class CythonUtilityCode(Code.UtilityCodeBase):
entries.pop('__builtins__')
entries.pop('__doc__')
for name, entry in entries.items():
for entry in entries.values():
entry.utility_code_definition = self
entry.used = used
original_scope = tree.scope
dest_scope.merge_in(original_scope, merge_unused=True,
whitelist=whitelist)
dest_scope.merge_in(original_scope, merge_unused=True, whitelist=whitelist)
tree.scope = dest_scope
for dep in self.requires:
......@@ -214,6 +208,7 @@ class CythonUtilityCode(Code.UtilityCodeBase):
return original_scope
def declare_declarations_in_scope(declaration_string, env, private_type=True,
*args, **kwargs):
"""
......
......@@ -77,9 +77,8 @@ class TreeVisitor(object):
self.access_path = []
def dump_node(self, node, indent=0):
ignored = list(node.child_attrs or []) + [u'child_attrs', u'pos',
u'gil_message', u'cpp_message',
u'subexprs']
ignored = list(node.child_attrs or []) + [
u'child_attrs', u'pos', u'gil_message', u'cpp_message', u'subexprs']
values = []
pos = getattr(node, 'pos', None)
if pos:
......@@ -93,7 +92,7 @@ class TreeVisitor(object):
for attr in attribute_names:
if attr in ignored:
continue
if attr.startswith(u'_') or attr.endswith(u'_'):
if attr.startswith('_') or attr.endswith('_'):
continue
try:
value = getattr(node, attr)
......@@ -108,8 +107,7 @@ class TreeVisitor(object):
else:
value = repr(value)
values.append(u'%s = %s' % (attr, value))
return u'%s(%s)' % (node.__class__.__name__,
u',\n '.join(values))
return u'%s(%s)' % (node.__class__.__name__, u',\n '.join(values))
def _find_node_path(self, stacktrace):
import os.path
......@@ -129,7 +127,6 @@ class TreeVisitor(object):
return (last_traceback, nodes)
def _raise_compiler_error(self, child, e):
import sys
trace = ['']
for parent, attribute, index in self.access_path:
node = getattr(parent, attribute)
......@@ -389,7 +386,7 @@ class EnvTransform(CythonTransform):
def visit_CArgDeclNode(self, node):
# default arguments are evaluated in the outer scope
if node.default:
attrs = [ attr for attr in node.child_attrs if attr != 'default' ]
attrs = [attr for attr in node.child_attrs if attr != 'default']
self.visitchildren(node, attrs)
self.enter_scope(node, self.current_env().outer_scope)
self.visitchildren(node, ('default',))
......
......@@ -110,7 +110,7 @@ cclass = ccall = cfunc = _EmptyDecoratorAndManager()
returns = wraparound = boundscheck = initializedcheck = nonecheck = \
overflowcheck = embedsignature = cdivision = cdivision_warnings = \
always_allows_keywords = profile = linetrace = infer_type = \
type_version_tag = unraisable_tracebacks = freelist = \
unraisable_tracebacks = freelist = \
lambda arg: _EmptyDecoratorAndManager()
optimization = _Optimization()
......@@ -120,6 +120,7 @@ overflowcheck.fold = optimization.use_switch = \
final = internal = type_version_tag = no_gc_clear = _empty_decorator
def inline(f, *args, **kwds):
if isinstance(f, basestring):
from Cython.Build.Inline import cython_inline
......@@ -128,10 +129,12 @@ def inline(f, *args, **kwds):
assert len(args) == len(kwds) == 0
return f
def compile(f):
from Cython.Build.Inline import RuntimeCompiledFunction
return RuntimeCompiledFunction(f)
# Special functions
def cdiv(a, b):
......
from Cython.Shadow import __version__
from __future__ import absolute_import
from .Shadow import __version__
# Void cython.* directives (for case insensitive operating systems).
from Cython.Shadow import *
from .Shadow import *
def load_ipython_extension(ip):
"""Load the extension in IPython."""
from Cython.Build.IpythonMagic import CythonMagics # pylint: disable=cyclic-import
from .Build.IpythonMagic import CythonMagics # pylint: disable=cyclic-import
ip.register_magics(CythonMagics)
......@@ -103,7 +103,7 @@ function-rgx=[a-z_][a-z0-9_]{2,30}$
method-rgx=[a-z_][a-z0-9_]{2,30}|visit_[A-Za-z]+$
# Regular expression which should only match correct instance attribute names
attr-rgx=[a-z_][a-z0-9_]{2,30}$
attr-rgx=[a-z_][a-z0-9_]{2,30}|sy$
# Regular expression which should only match correct argument names
argument-rgx=[a-z_][a-z0-9_]{0,30}$
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment