Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cython
Commits
52f5548e
Commit
52f5548e
authored
Sep 12, 2015
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make compile time DEF env less Py2/3 dependent
parent
9eac2bf3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
13 deletions
+30
-13
Cython/Compiler/Scanning.py
Cython/Compiler/Scanning.py
+19
-7
docs/src/userguide/language_basics.rst
docs/src/userguide/language_basics.rst
+11
-6
No files found.
Cython/Compiler/Scanning.py
View file @
52f5548e
...
...
@@ -103,13 +103,17 @@ def initial_compile_time_env():
except
ImportError
:
import
builtins
names
=
(
'False'
,
'True'
,
'abs'
,
'all'
,
'any'
,
'ascii'
,
'bin'
,
'bool'
,
'bytearray'
,
'bytes'
,
'chr'
,
'cmp'
,
'complex'
,
'dict'
,
'divmod'
,
'enumerate'
,
'filter'
,
'float'
,
'format'
,
'frozenset'
,
'hash'
,
'hex'
,
'int'
,
'len'
,
'list'
,
'long'
,
'map'
,
'max'
,
'min'
,
'oct'
,
'ord'
,
'pow'
,
'range'
,
'repr'
,
'reversed'
,
'round'
,
'set'
,
'slice'
,
'sorted'
,
'str'
,
'sum'
,
'tuple'
,
'xrange'
,
'zip'
)
names
=
(
'False'
,
'True'
,
'abs'
,
'all'
,
'any'
,
'ascii'
,
'bin'
,
'bool'
,
'bytearray'
,
'bytes'
,
'chr'
,
'cmp'
,
'complex'
,
'dict'
,
'divmod'
,
'enumerate'
,
'filter'
,
'float'
,
'format'
,
'frozenset'
,
'hash'
,
'hex'
,
'int'
,
'len'
,
'list'
,
'map'
,
'max'
,
'min'
,
'oct'
,
'ord'
,
'pow'
,
'range'
,
'repr'
,
'reversed'
,
'round'
,
'set'
,
'slice'
,
'sorted'
,
'str'
,
'sum'
,
'tuple'
,
'zip'
,
### defined below in a platform independent way
# 'long', 'unicode', 'reduce', 'xrange'
)
for
name
in
names
:
try
:
...
...
@@ -117,6 +121,14 @@ def initial_compile_time_env():
except
AttributeError
:
# ignore, likely Py3
pass
# Py2/3 adaptations
from
functools
import
reduce
benv
.
declare
(
'reduce'
,
reduce
)
benv
.
declare
(
'unicode'
,
getattr
(
builtins
,
'unicode'
,
getattr
(
builtins
,
'str'
)))
benv
.
declare
(
'long'
,
getattr
(
builtins
,
'long'
,
getattr
(
builtins
,
'int'
)))
benv
.
declare
(
'xrange'
,
getattr
(
builtins
,
'xrange'
,
getattr
(
builtins
,
'range'
)))
denv
=
CompileTimeScope
(
benv
)
return
denv
...
...
docs/src/userguide/language_basics.rst
View file @
52f5548e
...
...
@@ -569,7 +569,7 @@ Compile-Time Definitions
A compile-time constant can be defined using the DEF statement::
DEF FavouriteFood = "spam"
DEF FavouriteFood =
u
"spam"
DEF ArraySize = 42
DEF OtherArraySize = 2 * ArraySize + 17
...
...
@@ -586,16 +586,21 @@ returned by :func:`os.uname`.
The following selection of builtin constants and functions are also available:
None, True, False,
abs, bool, chr, cmp, complex, dict, divmod, enumerate,
float, hash, hex, int, len, list, long, map, max, min,
oct, ord, pow, range, reduce, repr, round, slice, str,
sum, tuple, xrange, zip
abs, all, any, ascii, bin, bool, bytearray, bytes, chr, cmp, complex, dict,
divmod, enumerate, filter, float, format, frozenset, hash, hex, int, len,
list, long, map, max, min, oct, ord, pow, range, reduce, repr, reversed,
round, set, slice, sorted, str, sum, tuple, xrange, zip
Note that some of these builtins may not be available when compiling under
Python 2.x or 3.x, or may behave differently in both.
A name defined using ``DEF`` can be used anywhere an identifier can appear,
and it is replaced with its compile-time value as though it were written into
the source at that point as a literal. For this to work, the compile-time
expression must evaluate to a Python value of type ``int``, ``long``,
``float`` or ``str``.::
``float``, ``bytes`` or ``unicode`` (``str`` in Py3).
::
cdef int a1[ArraySize]
cdef int a2[OtherArraySize]
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment