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):
quiet
=
quiet
,
annotate
=
args
.
annotate
,
force
=
True
,
language_level
=
min
(
3
,
sys
.
version_info
[
0
]),
)
if
args
.
language_level
is
not
None
:
assert
args
.
language_level
in
(
2
,
3
)
opts
[
'language_level'
]
=
args
.
language_level
elif
sys
.
version_info
[
0
]
>=
3
:
opts
[
'language_level'
]
=
3
return
cythonize
([
extension
],
**
opts
)
except
CompileError
:
return
None
...
...
Cython/Compiler/Code.py
View file @
3a5a2e3b
# cython: language_level
= 2
# cython: language_level
=3str
# cython: auto_pickle=False
#
# Code output module
...
...
Cython/Compiler/FlowControl.py
View file @
3a5a2e3b
# cython: language_level=3str
from
__future__
import
absolute_import
import
cython
...
...
Cython/Compiler/ParseTreeTransforms.py
View file @
3a5a2e3b
...
...
@@ -1572,7 +1572,7 @@ cdef class NAME:
count = 0
INIT_ASSIGNMENTS
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):
return STR_FORMAT % MEMBER_TUPLE
def __repr__(self):
...
...
Cython/Compiler/Parsing.py
View file @
3a5a2e3b
...
...
@@ -3688,12 +3688,12 @@ def p_module(s, pxd, full_module_name, ctx=Ctx):
s
.
parse_comments
=
False
if
s
.
context
.
language_level
is
None
:
s
.
context
.
set_language_level
(
2
)
s
.
context
.
set_language_level
(
'3str'
)
if
pos
[
0
].
filename
:
import
warnings
warnings
.
warn
(
"Cython directive 'language_level' not set, using
2 for now (Py2
). "
"This
will change in a later release
! File: %s"
%
pos
[
0
].
filename
,
"Cython directive 'language_level' not set, using
'3str' for now (Py3
). "
"This
has changed from earlier releases
! File: %s"
%
pos
[
0
].
filename
,
FutureWarning
,
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/Compiler/TreeFragment.py
View file @
3a5a2e3b
...
...
@@ -29,8 +29,7 @@ class StringParseContext(Main.Context):
include_directories
=
[]
if
compiler_directives
is
None
:
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
=
2
)
Main
.
Context
.
__init__
(
self
,
include_directories
,
compiler_directives
,
cpp
=
cpp
,
language_level
=
'3str'
)
self
.
module_name
=
name
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
#=======================================================================
#
...
...
@@ -31,7 +32,7 @@ class Return(Action):
return
isinstance
(
other
,
Return
)
and
self
.
value
==
other
.
value
def
__repr__
(
self
):
return
"Return(%
s)"
%
repr
(
self
.
value
)
return
"Return(%
r)"
%
self
.
value
class
Call
(
Action
):
...
...
Cython/Plex/Scanners.py
View file @
3a5a2e3b
# cython: language_level=3str
# cython: auto_pickle=False
#=======================================================================
#
...
...
Cython/Tempita/_tempita.py
View file @
3a5a2e3b
# cython: language_level=3str
"""
A small templating language
...
...
Cython/Tests/TestCodeWriter.py
View file @
3a5a2e3b
...
...
@@ -19,9 +19,8 @@ class TestCodeWriter(CythonTest):
def
test_print
(
self
):
self
.
t
(
u"""
print x, y
print x + y ** 2
print x, y, z,
print(x + y ** 2)
print(x, y, z)
"""
)
def
test_if
(
self
):
...
...
@@ -65,9 +64,9 @@ class TestCodeWriter(CythonTest):
def
test_for_loop
(
self
):
self
.
t
(
u"""
for x, y, z in f(g(h(34) * 2) + 23):
print
x, y, z
print
(x, y, z)
else:
print
43
print
(43)
"""
)
def
test_inplace_assignment
(
self
):
...
...
Cython/Utility/CpdefEnums.pyx
View file @
3a5a2e3b
...
...
@@ -20,8 +20,7 @@ cdef class __Pyx_EnumMeta(type):
# @cython.internal
cdef
object
__Pyx_EnumBase
class
__Pyx_EnumBase
(
int
):
__metaclass__
=
__Pyx_EnumMeta
class
__Pyx_EnumBase
(
int
,
metaclass
=
__Pyx_EnumMeta
):
def
__new__
(
cls
,
value
,
name
=
None
):
for
v
in
cls
:
if
v
==
value
:
...
...
Cython/Utility/MemoryView.pyx
View file @
3a5a2e3b
...
...
@@ -177,7 +177,7 @@ cdef class array:
if
self
.
dtype_is_object
:
p
=
<
PyObject
**>
self
.
data
for
i
in
range
(
self
.
len
/
itemsize
):
for
i
in
range
(
self
.
len
/
/
itemsize
):
p
[
i
]
=
Py_None
Py_INCREF
(
Py_None
)
...
...
@@ -910,7 +910,7 @@ cdef char *pybuffer_index(Py_buffer *view, char *bufp, Py_ssize_t index,
cdef
char
*
resultp
if
view
.
ndim
==
0
:
shape
=
view
.
len
/
itemsize
shape
=
view
.
len
/
/
itemsize
stride
=
itemsize
else
:
shape
=
view
.
shape
[
dim
]
...
...
@@ -944,7 +944,7 @@ cdef int transpose_memslice({{memviewslice_name}} *memslice) nogil except 0:
# reverse strides and shape
cdef
int
i
,
j
for
i
in
range
(
ndim
/
2
):
for
i
in
range
(
ndim
/
/
2
):
j
=
ndim
-
1
-
i
strides
[
i
],
strides
[
j
]
=
strides
[
j
],
strides
[
i
]
shape
[
i
],
shape
[
j
]
=
shape
[
j
],
shape
[
i
]
...
...
Cython/Utility/TestCythonScope.pyx
View file @
3a5a2e3b
########## TestClass ##########
# These utilities are for testing purposes
from
__future__
import
print_function
cdef
extern
from
*
:
cdef
object
__pyx_test_dep
(
object
)
...
...
@@ -15,29 +17,29 @@ cdef class TestClass(object):
return
'TestClass(%d)'
%
self
.
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
):
print
'Hello from cpdef_method'
,
value
print
(
'Hello from cpdef_method'
,
value
)
def
def_method
(
self
,
int
value
):
print
'Hello from def_method'
,
value
print
(
'Hello from def_method'
,
value
)
@
cname
(
'cdef_cname'
)
cdef
cdef
_cname_method
(
self
,
int
value
):
print
"Hello from cdef_cname_method"
,
value
print
(
"Hello from cdef_cname_method"
,
value
)
@
cname
(
'cpdef_cname'
)
cpdef
cpdef
_cname_method
(
self
,
int
value
):
print
"Hello from cpdef_cname_method"
,
value
print
(
"Hello from cpdef_cname_method"
,
value
)
@
cname
(
'def_cname'
)
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'
)
cdef
test_call
(
obj
):
print
'test_call'
print
(
'test_call'
)
__pyx_test_dep
(
obj
)
@
cname
(
'__pyx_TestClass_New'
)
...
...
@@ -46,19 +48,20 @@ cdef _testclass_new(int value):
########### TestDep ##########
from
__future__
import
print_function
@
cname
(
'__pyx_test_dep'
)
cdef
test_dep
(
obj
):
print
'test_dep'
,
obj
print
(
'test_dep'
,
obj
)
########## TestScope ##########
@
cname
(
'__pyx_testscope'
)
cdef
object
_testscope
(
int
value
):
return
"hello from cython scope, value=%d"
%
value
return
f"hello from cython scope, value=
{
value
}
"
########## View.TestScope ##########
@
cname
(
'__pyx_view_testscope'
)
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 {
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
cdef array a = array('i', [1,2,3])
cdef Foo x
print
a.data.as_ints[0]
print
(a.data.as_ints[0])
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 (
A,
foo,
)
print
A, foo(10
)
print
(A, foo(10)
)
cimport other
print
other.A, other.foo(10
)
print
(other.A, other.foo(10)
)
from pkg cimport sub
cdef sub.my_int a = 100
from pkg.subpkg cimport submod
\ No newline at end of file
from pkg.subpkg cimport submod
tests/run/cimport_from_sys_path.srctree
View file @
3a5a2e3b
...
...
@@ -32,7 +32,7 @@ static int foo(int a)
######## a.pyx ########
from b.other cimport foo
print
foo(10
)
print
(foo(10)
)
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:
traceback.print_exc()
def test():
print
"FILE: ", initial_file
print
"PATH: ", initial_path
print
("FILE: ", initial_file)
print
("PATH: ", initial_path)
assert initial_path[0].endswith('my_test_package'), initial_path
assert initial_file.endswith('__init__.py'), initial_file
assert import_error is None, import_error
...
...
@@ -51,8 +51,8 @@ except ImportError as e:
traceback.print_exc()
def test():
print
"FILE: ", initial_file
print
"PATH: ", initial_path
print
("FILE: ", initial_file)
print
("PATH: ", initial_path)
assert initial_path[0].endswith('another'), initial_path
assert initial_file.endswith('__init__.py'), initial_file
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
def ae(result, expected):
"assert equals"
if result != expected:
print
'result :', result
print
'expected:', expected
print
('result :', result)
print
('expected:', expected)
assert result == expected
...
...
@@ -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}
exec
s in d
exec
(s, d)
# Test def methods
# ae(obj.def_method(12, 14.9), 26)
...
...
tests/run/relative_cimport.srctree
View file @
3a5a2e3b
...
...
@@ -3,6 +3,7 @@
PYTHON setup.py build_ext --inplace
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)"
######## setup.py ########
...
...
@@ -42,7 +43,23 @@ cdef class test_pxd:
from . cimport a
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 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