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
3a5a2e3b
Commit
3a5a2e3b
authored
Jan 14, 2019
by
Stefan Behnel
Committed by
GitHub
Jan 14, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2796 from cython/gh2565_language_level_3str
Change the default language level to "3str"
parents
96403849
c597e501
Changes
21
Hide whitespace changes
Inline
Side-by-side
Showing
21 changed files
with
70 additions
and
48 deletions
+70
-48
Cython/Build/IpythonMagic.py
Cython/Build/IpythonMagic.py
+1
-2
Cython/Compiler/Code.py
Cython/Compiler/Code.py
+1
-1
Cython/Compiler/FlowControl.py
Cython/Compiler/FlowControl.py
+2
-0
Cython/Compiler/ParseTreeTransforms.py
Cython/Compiler/ParseTreeTransforms.py
+1
-1
Cython/Compiler/Parsing.py
Cython/Compiler/Parsing.py
+3
-3
Cython/Compiler/Scanning.py
Cython/Compiler/Scanning.py
+1
-1
Cython/Compiler/TreeFragment.py
Cython/Compiler/TreeFragment.py
+1
-2
Cython/Plex/Actions.py
Cython/Plex/Actions.py
+2
-1
Cython/Plex/Scanners.py
Cython/Plex/Scanners.py
+1
-0
Cython/Tempita/_tempita.py
Cython/Tempita/_tempita.py
+2
-0
Cython/Tests/TestCodeWriter.py
Cython/Tests/TestCodeWriter.py
+4
-5
Cython/Utility/CpdefEnums.pyx
Cython/Utility/CpdefEnums.pyx
+1
-2
Cython/Utility/MemoryView.pyx
Cython/Utility/MemoryView.pyx
+3
-3
Cython/Utility/TestCythonScope.pyx
Cython/Utility/TestCythonScope.pyx
+14
-11
tests/build/inline_distutils.srctree
tests/build/inline_distutils.srctree
+1
-1
tests/run/array_cimport.srctree
tests/run/array_cimport.srctree
+2
-2
tests/run/cimport.srctree
tests/run/cimport.srctree
+3
-3
tests/run/cimport_from_sys_path.srctree
tests/run/cimport_from_sys_path.srctree
+2
-2
tests/run/initial_file_path.srctree
tests/run/initial_file_path.srctree
+4
-4
tests/run/public_fused_types.srctree
tests/run/public_fused_types.srctree
+3
-3
tests/run/relative_cimport.srctree
tests/run/relative_cimport.srctree
+18
-1
No files found.
Cython/Build/IpythonMagic.py
View file @
3a5a2e3b
...
@@ -419,12 +419,11 @@ class CythonMagics(Magics):
...
@@ -419,12 +419,11 @@ class CythonMagics(Magics):
quiet
=
quiet
,
quiet
=
quiet
,
annotate
=
args
.
annotate
,
annotate
=
args
.
annotate
,
force
=
True
,
force
=
True
,
language_level
=
min
(
3
,
sys
.
version_info
[
0
]),
)
)
if
args
.
language_level
is
not
None
:
if
args
.
language_level
is
not
None
:
assert
args
.
language_level
in
(
2
,
3
)
assert
args
.
language_level
in
(
2
,
3
)
opts
[
'language_level'
]
=
args
.
language_level
opts
[
'language_level'
]
=
args
.
language_level
elif
sys
.
version_info
[
0
]
>=
3
:
opts
[
'language_level'
]
=
3
return
cythonize
([
extension
],
**
opts
)
return
cythonize
([
extension
],
**
opts
)
except
CompileError
:
except
CompileError
:
return
None
return
None
...
...
Cython/Compiler/Code.py
View file @
3a5a2e3b
# cython: language_level
= 2
# cython: language_level
=3str
# cython: auto_pickle=False
# cython: auto_pickle=False
#
#
# Code output module
# Code output module
...
...
Cython/Compiler/FlowControl.py
View file @
3a5a2e3b
# cython: language_level=3str
from
__future__
import
absolute_import
from
__future__
import
absolute_import
import
cython
import
cython
...
...
Cython/Compiler/ParseTreeTransforms.py
View file @
3a5a2e3b
...
@@ -1572,7 +1572,7 @@ cdef class NAME:
...
@@ -1572,7 +1572,7 @@ cdef class NAME:
count = 0
count = 0
INIT_ASSIGNMENTS
INIT_ASSIGNMENTS
if IS_UNION and count > 1:
if IS_UNION and count > 1:
raise ValueError
, "At most one union member should be specified."
raise ValueError
("At most one union member should be specified.")
def __str__(self):
def __str__(self):
return STR_FORMAT % MEMBER_TUPLE
return STR_FORMAT % MEMBER_TUPLE
def __repr__(self):
def __repr__(self):
...
...
Cython/Compiler/Parsing.py
View file @
3a5a2e3b
...
@@ -3688,12 +3688,12 @@ def p_module(s, pxd, full_module_name, ctx=Ctx):
...
@@ -3688,12 +3688,12 @@ def p_module(s, pxd, full_module_name, ctx=Ctx):
s
.
parse_comments
=
False
s
.
parse_comments
=
False
if
s
.
context
.
language_level
is
None
:
if
s
.
context
.
language_level
is
None
:
s
.
context
.
set_language_level
(
2
)
s
.
context
.
set_language_level
(
'3str'
)
if
pos
[
0
].
filename
:
if
pos
[
0
].
filename
:
import
warnings
import
warnings
warnings
.
warn
(
warnings
.
warn
(
"Cython directive 'language_level' not set, using
2 for now (Py2
). "
"Cython directive 'language_level' not set, using
'3str' for now (Py3
). "
"This
will change in a later release
! File: %s"
%
pos
[
0
].
filename
,
"This
has changed from earlier releases
! File: %s"
%
pos
[
0
].
filename
,
FutureWarning
,
FutureWarning
,
stacklevel
=
1
if
cython
.
compiled
else
2
,
stacklevel
=
1
if
cython
.
compiled
else
2
,
)
)
...
...
Cython/Compiler/Scanning.py
View file @
3a5a2e3b
# cython: infer_types=True, language_level=3,
py2_import=True,
auto_pickle=False
# cython: infer_types=True, language_level=3, auto_pickle=False
#
#
# Cython Scanner
# Cython Scanner
#
#
...
...
Cython/Compiler/TreeFragment.py
View file @
3a5a2e3b
...
@@ -29,8 +29,7 @@ class StringParseContext(Main.Context):
...
@@ -29,8 +29,7 @@ class StringParseContext(Main.Context):
include_directories
=
[]
include_directories
=
[]
if
compiler_directives
is
None
:
if
compiler_directives
is
None
:
compiler_directives
=
{}
compiler_directives
=
{}
# TODO: see if "language_level=3" also works for our internal code here.
Main
.
Context
.
__init__
(
self
,
include_directories
,
compiler_directives
,
cpp
=
cpp
,
language_level
=
'3str'
)
Main
.
Context
.
__init__
(
self
,
include_directories
,
compiler_directives
,
cpp
=
cpp
,
language_level
=
2
)
self
.
module_name
=
name
self
.
module_name
=
name
def
find_module
(
self
,
module_name
,
relative_to
=
None
,
pos
=
None
,
need_pxd
=
1
,
absolute_fallback
=
True
):
def
find_module
(
self
,
module_name
,
relative_to
=
None
,
pos
=
None
,
need_pxd
=
1
,
absolute_fallback
=
True
):
...
...
Cython/Plex/Actions.py
View file @
3a5a2e3b
# cython: language_level=3str
# cython: auto_pickle=False
# cython: auto_pickle=False
#=======================================================================
#=======================================================================
#
#
...
@@ -31,7 +32,7 @@ class Return(Action):
...
@@ -31,7 +32,7 @@ class Return(Action):
return
isinstance
(
other
,
Return
)
and
self
.
value
==
other
.
value
return
isinstance
(
other
,
Return
)
and
self
.
value
==
other
.
value
def
__repr__
(
self
):
def
__repr__
(
self
):
return
"Return(%
s)"
%
repr
(
self
.
value
)
return
"Return(%
r)"
%
self
.
value
class
Call
(
Action
):
class
Call
(
Action
):
...
...
Cython/Plex/Scanners.py
View file @
3a5a2e3b
# cython: language_level=3str
# cython: auto_pickle=False
# cython: auto_pickle=False
#=======================================================================
#=======================================================================
#
#
...
...
Cython/Tempita/_tempita.py
View file @
3a5a2e3b
# cython: language_level=3str
"""
"""
A small templating language
A small templating language
...
...
Cython/Tests/TestCodeWriter.py
View file @
3a5a2e3b
...
@@ -19,9 +19,8 @@ class TestCodeWriter(CythonTest):
...
@@ -19,9 +19,8 @@ class TestCodeWriter(CythonTest):
def
test_print
(
self
):
def
test_print
(
self
):
self
.
t
(
u"""
self
.
t
(
u"""
print x, y
print(x + y ** 2)
print x + y ** 2
print(x, y, z)
print x, y, z,
"""
)
"""
)
def
test_if
(
self
):
def
test_if
(
self
):
...
@@ -65,9 +64,9 @@ class TestCodeWriter(CythonTest):
...
@@ -65,9 +64,9 @@ class TestCodeWriter(CythonTest):
def
test_for_loop
(
self
):
def
test_for_loop
(
self
):
self
.
t
(
u"""
self
.
t
(
u"""
for x, y, z in f(g(h(34) * 2) + 23):
for x, y, z in f(g(h(34) * 2) + 23):
print
x, y, z
print
(x, y, z)
else:
else:
print
43
print
(43)
"""
)
"""
)
def
test_inplace_assignment
(
self
):
def
test_inplace_assignment
(
self
):
...
...
Cython/Utility/CpdefEnums.pyx
View file @
3a5a2e3b
...
@@ -20,8 +20,7 @@ cdef class __Pyx_EnumMeta(type):
...
@@ -20,8 +20,7 @@ cdef class __Pyx_EnumMeta(type):
# @cython.internal
# @cython.internal
cdef
object
__Pyx_EnumBase
cdef
object
__Pyx_EnumBase
class
__Pyx_EnumBase
(
int
):
class
__Pyx_EnumBase
(
int
,
metaclass
=
__Pyx_EnumMeta
):
__metaclass__
=
__Pyx_EnumMeta
def
__new__
(
cls
,
value
,
name
=
None
):
def
__new__
(
cls
,
value
,
name
=
None
):
for
v
in
cls
:
for
v
in
cls
:
if
v
==
value
:
if
v
==
value
:
...
...
Cython/Utility/MemoryView.pyx
View file @
3a5a2e3b
...
@@ -177,7 +177,7 @@ cdef class array:
...
@@ -177,7 +177,7 @@ cdef class array:
if
self
.
dtype_is_object
:
if
self
.
dtype_is_object
:
p
=
<
PyObject
**>
self
.
data
p
=
<
PyObject
**>
self
.
data
for
i
in
range
(
self
.
len
/
itemsize
):
for
i
in
range
(
self
.
len
/
/
itemsize
):
p
[
i
]
=
Py_None
p
[
i
]
=
Py_None
Py_INCREF
(
Py_None
)
Py_INCREF
(
Py_None
)
...
@@ -910,7 +910,7 @@ cdef char *pybuffer_index(Py_buffer *view, char *bufp, Py_ssize_t index,
...
@@ -910,7 +910,7 @@ cdef char *pybuffer_index(Py_buffer *view, char *bufp, Py_ssize_t index,
cdef
char
*
resultp
cdef
char
*
resultp
if
view
.
ndim
==
0
:
if
view
.
ndim
==
0
:
shape
=
view
.
len
/
itemsize
shape
=
view
.
len
/
/
itemsize
stride
=
itemsize
stride
=
itemsize
else
:
else
:
shape
=
view
.
shape
[
dim
]
shape
=
view
.
shape
[
dim
]
...
@@ -944,7 +944,7 @@ cdef int transpose_memslice({{memviewslice_name}} *memslice) nogil except 0:
...
@@ -944,7 +944,7 @@ cdef int transpose_memslice({{memviewslice_name}} *memslice) nogil except 0:
# reverse strides and shape
# reverse strides and shape
cdef
int
i
,
j
cdef
int
i
,
j
for
i
in
range
(
ndim
/
2
):
for
i
in
range
(
ndim
/
/
2
):
j
=
ndim
-
1
-
i
j
=
ndim
-
1
-
i
strides
[
i
],
strides
[
j
]
=
strides
[
j
],
strides
[
i
]
strides
[
i
],
strides
[
j
]
=
strides
[
j
],
strides
[
i
]
shape
[
i
],
shape
[
j
]
=
shape
[
j
],
shape
[
i
]
shape
[
i
],
shape
[
j
]
=
shape
[
j
],
shape
[
i
]
...
...
Cython/Utility/TestCythonScope.pyx
View file @
3a5a2e3b
########## TestClass ##########
########## TestClass ##########
# These utilities are for testing purposes
# These utilities are for testing purposes
from
__future__
import
print_function
cdef
extern
from
*
:
cdef
extern
from
*
:
cdef
object
__pyx_test_dep
(
object
)
cdef
object
__pyx_test_dep
(
object
)
...
@@ -15,29 +17,29 @@ cdef class TestClass(object):
...
@@ -15,29 +17,29 @@ cdef class TestClass(object):
return
'TestClass(%d)'
%
self
.
value
return
'TestClass(%d)'
%
self
.
value
cdef
cdef
_method
(
self
,
int
value
):
cdef
cdef
_method
(
self
,
int
value
):
print
'Hello from cdef_method'
,
value
print
(
'Hello from cdef_method'
,
value
)
cpdef
cpdef
_method
(
self
,
int
value
):
cpdef
cpdef
_method
(
self
,
int
value
):
print
'Hello from cpdef_method'
,
value
print
(
'Hello from cpdef_method'
,
value
)
def
def_method
(
self
,
int
value
):
def
def_method
(
self
,
int
value
):
print
'Hello from def_method'
,
value
print
(
'Hello from def_method'
,
value
)
@
cname
(
'cdef_cname'
)
@
cname
(
'cdef_cname'
)
cdef
cdef
_cname_method
(
self
,
int
value
):
cdef
cdef
_cname_method
(
self
,
int
value
):
print
"Hello from cdef_cname_method"
,
value
print
(
"Hello from cdef_cname_method"
,
value
)
@
cname
(
'cpdef_cname'
)
@
cname
(
'cpdef_cname'
)
cpdef
cpdef
_cname_method
(
self
,
int
value
):
cpdef
cpdef
_cname_method
(
self
,
int
value
):
print
"Hello from cpdef_cname_method"
,
value
print
(
"Hello from cpdef_cname_method"
,
value
)
@
cname
(
'def_cname'
)
@
cname
(
'def_cname'
)
def
def_cname_method
(
self
,
int
value
):
def
def_cname_method
(
self
,
int
value
):
print
"Hello from def_cname_method"
,
value
print
(
"Hello from def_cname_method"
,
value
)
@
cname
(
'__pyx_test_call_other_cy_util'
)
@
cname
(
'__pyx_test_call_other_cy_util'
)
cdef
test_call
(
obj
):
cdef
test_call
(
obj
):
print
'test_call'
print
(
'test_call'
)
__pyx_test_dep
(
obj
)
__pyx_test_dep
(
obj
)
@
cname
(
'__pyx_TestClass_New'
)
@
cname
(
'__pyx_TestClass_New'
)
...
@@ -46,19 +48,20 @@ cdef _testclass_new(int value):
...
@@ -46,19 +48,20 @@ cdef _testclass_new(int value):
########### TestDep ##########
########### TestDep ##########
from
__future__
import
print_function
@
cname
(
'__pyx_test_dep'
)
@
cname
(
'__pyx_test_dep'
)
cdef
test_dep
(
obj
):
cdef
test_dep
(
obj
):
print
'test_dep'
,
obj
print
(
'test_dep'
,
obj
)
########## TestScope ##########
########## TestScope ##########
@
cname
(
'__pyx_testscope'
)
@
cname
(
'__pyx_testscope'
)
cdef
object
_testscope
(
int
value
):
cdef
object
_testscope
(
int
value
):
return
"hello from cython scope, value=%d"
%
value
return
f"hello from cython scope, value=
{
value
}
"
########## View.TestScope ##########
########## View.TestScope ##########
@
cname
(
'__pyx_view_testscope'
)
@
cname
(
'__pyx_view_testscope'
)
cdef
object
_testscope
(
int
value
):
cdef
object
_testscope
(
int
value
):
return
"hello from cython.view scope, value=%d"
%
value
return
f"hello from cython.view scope, value=
{
value
}
"
tests/build/inline_distutils.srctree
View file @
3a5a2e3b
...
@@ -38,4 +38,4 @@ namespace A {
...
@@ -38,4 +38,4 @@ namespace A {
from my_lib cimport x
from my_lib cimport x
print
x
print
(x)
tests/run/array_cimport.srctree
View file @
3a5a2e3b
...
@@ -32,6 +32,6 @@ from tt cimport Foo
...
@@ -32,6 +32,6 @@ from tt cimport Foo
cdef array a = array('i', [1,2,3])
cdef array a = array('i', [1,2,3])
cdef Foo x
cdef Foo x
print
a.data.as_ints[0]
print
(a.data.as_ints[0])
x = Foo(a)
x = Foo(a)
print
x.obj.data.as_ints[0]
print
(x.obj.data.as_ints[0])
tests/run/cimport.srctree
View file @
3a5a2e3b
...
@@ -45,12 +45,12 @@ from other cimport (
...
@@ -45,12 +45,12 @@ from other cimport (
A,
A,
foo,
foo,
)
)
print
A, foo(10
)
print
(A, foo(10)
)
cimport other
cimport other
print
other.A, other.foo(10
)
print
(other.A, other.foo(10)
)
from pkg cimport sub
from pkg cimport sub
cdef sub.my_int a = 100
cdef sub.my_int a = 100
from pkg.subpkg cimport submod
from pkg.subpkg cimport submod
\ No newline at end of file
tests/run/cimport_from_sys_path.srctree
View file @
3a5a2e3b
...
@@ -32,7 +32,7 @@ static int foo(int a)
...
@@ -32,7 +32,7 @@ static int foo(int a)
######## a.pyx ########
######## a.pyx ########
from b.other cimport foo
from b.other cimport foo
print
foo(10
)
print
(foo(10)
)
cimport b.other
cimport b.other
print
b.other.foo(10
)
print
(b.other.foo(10)
)
tests/run/initial_file_path.srctree
View file @
3a5a2e3b
...
@@ -29,8 +29,8 @@ except ImportError as e:
...
@@ -29,8 +29,8 @@ except ImportError as e:
traceback.print_exc()
traceback.print_exc()
def test():
def test():
print
"FILE: ", initial_file
print
("FILE: ", initial_file)
print
"PATH: ", initial_path
print
("PATH: ", initial_path)
assert initial_path[0].endswith('my_test_package'), initial_path
assert initial_path[0].endswith('my_test_package'), initial_path
assert initial_file.endswith('__init__.py'), initial_file
assert initial_file.endswith('__init__.py'), initial_file
assert import_error is None, import_error
assert import_error is None, import_error
...
@@ -51,8 +51,8 @@ except ImportError as e:
...
@@ -51,8 +51,8 @@ except ImportError as e:
traceback.print_exc()
traceback.print_exc()
def test():
def test():
print
"FILE: ", initial_file
print
("FILE: ", initial_file)
print
"PATH: ", initial_path
print
("PATH: ", initial_path)
assert initial_path[0].endswith('another'), initial_path
assert initial_path[0].endswith('another'), initial_path
assert initial_file.endswith('__init__.py'), initial_file
assert initial_file.endswith('__init__.py'), initial_file
assert import_error is None, import_error
assert import_error is None, import_error
...
...
tests/run/public_fused_types.srctree
View file @
3a5a2e3b
...
@@ -196,8 +196,8 @@ import a as a_mod
...
@@ -196,8 +196,8 @@ import a as a_mod
def ae(result, expected):
def ae(result, expected):
"assert equals"
"assert equals"
if result != expected:
if result != expected:
print
'result :', result
print
('result :', result)
print
'expected:', expected
print
('expected:', expected)
assert result == expected
assert result == expected
...
@@ -227,7 +227,7 @@ ae(myobj.cpdef_method[cy.int, cy.float](10, 10.0), (10, 10.0))
...
@@ -227,7 +227,7 @@ ae(myobj.cpdef_method[cy.int, cy.float](10, 10.0), (10, 10.0))
d = {'obj': obj, 'myobj': myobj, 'ae': ae}
d = {'obj': obj, 'myobj': myobj, 'ae': ae}
exec
s in d
exec
(s, d)
# Test def methods
# Test def methods
# ae(obj.def_method(12, 14.9), 26)
# ae(obj.def_method(12, 14.9), 26)
...
...
tests/run/relative_cimport.srctree
View file @
3a5a2e3b
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
PYTHON setup.py build_ext --inplace
PYTHON setup.py build_ext --inplace
PYTHON -c "from pkg.b import test; assert test() == (1, 2)"
PYTHON -c "from pkg.b import test; assert test() == (1, 2)"
PYTHON -c "from pkg.b_py2 import test; assert test() == (1, 2)"
PYTHON -c "from pkg.sub.c import test; assert test() == (1, 2)"
PYTHON -c "from pkg.sub.c import test; assert test() == (1, 2)"
######## setup.py ########
######## setup.py ########
...
@@ -42,7 +43,23 @@ cdef class test_pxd:
...
@@ -42,7 +43,23 @@ cdef class test_pxd:
from . cimport a
from . cimport a
from .a cimport test_pxd
from .a cimport test_pxd
cimport a as implicitly_relative_a
assert a.test_pxd is test_pxd
def test():
cdef test_pxd obj = test_pxd()
obj.x = 1
obj.y = 2
return (obj.x, obj.y)
######## pkg/b_py2.pyx ########
# cython: language_level=2
from . cimport a
from .a cimport test_pxd
cimport a as implicitly_relative_a # <-- Py2 "feature"
assert a.test_pxd is test_pxd
assert a.test_pxd is test_pxd
assert implicitly_relative_a.test_pxd is test_pxd
assert implicitly_relative_a.test_pxd is test_pxd
...
...
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