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
Boxiang Sun
cython
Commits
1a0c1320
Commit
1a0c1320
authored
Sep 26, 2017
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Prevent unknown names in annotations from being interpreted (and declared!) as builtins.
Closes #1887.
parent
70fc8bb1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
5 deletions
+24
-5
Cython/Compiler/ExprNodes.py
Cython/Compiler/ExprNodes.py
+4
-5
tests/run/annotation_typing.pyx
tests/run/annotation_typing.pyx
+20
-0
No files found.
Cython/Compiler/ExprNodes.py
View file @
1a0c1320
...
...
@@ -1362,18 +1362,17 @@ def _analyse_name_as_type(name, pos, env):
type
=
PyrexTypes
.
parse_basic_type
(
name
)
if
type
is
not
None
:
return
type
from
.TreeFragment
import
TreeFragment
with
local_errors
(
ignore
=
True
):
from
.TreeFragment
import
TreeFragment
pos
=
(
pos
[
0
],
pos
[
1
],
pos
[
2
]
-
7
)
try
:
declaration
=
TreeFragment
(
u"sizeof(%s)"
%
name
,
name
=
pos
[
0
].
filename
,
initial_pos
=
pos
)
except
CompileError
:
sizeof_node
=
None
pass
else
:
sizeof_node
=
declaration
.
root
.
stats
[
0
].
expr
sizeof_node
=
sizeof_node
.
analyse_types
(
env
)
if
isinstance
(
sizeof_node
,
SizeofTypeNode
):
return
sizeof_node
.
arg_type
if
isinstance
(
sizeof_node
,
SizeofTypeNode
):
return
sizeof_node
.
arg_type
.
analyse_types
(
env
)
return
None
...
...
tests/run/annotation_typing.pyx
View file @
1a0c1320
...
...
@@ -196,6 +196,25 @@ def call_exception_default(raise_exc=False):
return
exception_default
(
raise_exc
)
class
EarlyClass
(
object
):
"""
>>> a = EarlyClass(1)
>>> a.string_forward_declaration() # should probably raise an error at some point
1
>>> x = LateClass()
>>> a = EarlyClass(x)
>>> x2 = a.string_forward_declaration()
>>> assert x is x2, x2
"""
def
__init__
(
self
,
x
):
self
.
x
=
x
def
string_forward_declaration
(
self
)
->
'LateClass'
:
return
self
.
x
class
LateClass
(
object
):
pass
_WARNINGS
=
"""
8:32: Strings should no longer be used for type declarations. Use 'cython.int' etc. directly.
8:47: Dicts should no longer be used as type annotations. Use 'cython.int' etc. directly.
...
...
@@ -203,6 +222,7 @@ _WARNINGS = """
8:77: Dicts should no longer be used as type annotations. Use 'cython.int' etc. directly.
8:85: Python type declaration in signature annotation does not refer to a Python type
8:85: Strings should no longer be used for type declarations. Use 'cython.int' etc. directly.
211:44: Unknown type declaration in annotation, ignoring
# BUG:
46:6: 'pytypes_cpdef' redeclared
121:0: 'struct_io' redeclared
...
...
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