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
Gwenaël Samain
cython
Commits
b3201262
Commit
b3201262
authored
Apr 13, 2013
by
Nikita Nemkin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Show attribute access and binary operations in default values in autogenerated signatures.
parent
58131b68
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
65 additions
and
2 deletions
+65
-2
Cython/Compiler/AutoDocTransforms.py
Cython/Compiler/AutoDocTransforms.py
+36
-2
tests/run/embedsignatures.pyx
tests/run/embedsignatures.pyx
+29
-0
No files found.
Cython/Compiler/AutoDocTransforms.py
View file @
b3201262
...
@@ -11,6 +11,40 @@ class EmbedSignature(CythonTransform):
...
@@ -11,6 +11,40 @@ class EmbedSignature(CythonTransform):
self
.
class_name
=
None
self
.
class_name
=
None
self
.
class_node
=
None
self
.
class_node
=
None
unop_precedence
=
11
binop_precedence
=
{
'or'
:
1
,
'and'
:
2
,
'not'
:
3
,
'in'
:
4
,
'not in'
:
4
,
'is'
:
4
,
'is not'
:
4
,
'<'
:
4
,
'<='
:
4
,
'>'
:
4
,
'>='
:
4
,
'!='
:
4
,
'=='
:
4
,
'|'
:
5
,
'^'
:
6
,
'&'
:
7
,
'<<'
:
8
,
'>>'
:
8
,
'+'
:
9
,
'-'
:
9
,
'*'
:
10
,
'/'
:
10
,
'//'
:
10
,
'%'
:
10
,
# unary: '+': 11, '-': 11, '~': 11
'**'
:
12
}
def
_fmt_expr_node
(
self
,
node
,
precedence
=
0
):
if
isinstance
(
node
,
ExprNodes
.
BinopNode
)
and
not
node
.
inplace
:
new_prec
=
self
.
binop_precedence
.
get
(
node
.
operator
,
0
)
result
=
'%s %s %s'
%
(
self
.
_fmt_expr_node
(
node
.
operand1
,
new_prec
),
node
.
operator
,
self
.
_fmt_expr_node
(
node
.
operand2
,
new_prec
))
if
precedence
>
new_prec
:
result
=
'(%s)'
%
result
elif
isinstance
(
node
,
ExprNodes
.
UnopNode
):
result
=
'%s%s'
%
(
node
.
operator
,
self
.
_fmt_expr_node
(
node
.
operand
,
self
.
unop_precedence
))
if
precedence
>
self
.
unop_precedence
:
result
=
'(%s)'
%
result
elif
isinstance
(
node
,
ExprNodes
.
AttributeNode
):
result
=
'%s.%s'
%
(
self
.
_fmt_expr_node
(
node
.
obj
),
node
.
attribute
)
else
:
result
=
node
.
name
return
result
def
_fmt_arg_defv
(
self
,
arg
):
def
_fmt_arg_defv
(
self
,
arg
):
default_val
=
arg
.
default
default_val
=
arg
.
default
if
not
default_val
:
if
not
default_val
:
...
@@ -31,8 +65,8 @@ class EmbedSignature(CythonTransform):
...
@@ -31,8 +65,8 @@ class EmbedSignature(CythonTransform):
return
repr_val
return
repr_val
except
Exception
:
except
Exception
:
try
:
try
:
return
default_val
.
name
# XXX
return
self
.
_fmt_expr_node
(
default_val
)
except
AttributeError
:
except
AttributeError
,
e
:
return
'<???>'
return
'<???>'
def
_fmt_arg
(
self
,
arg
):
def
_fmt_arg
(
self
,
arg
):
...
...
tests/run/embedsignatures.pyx
View file @
b3201262
...
@@ -150,6 +150,17 @@ __doc__ = ur"""
...
@@ -150,6 +150,17 @@ __doc__ = ur"""
>>> print (f_my_f.__doc__)
>>> print (f_my_f.__doc__)
f_my_f(MyFloat f) -> MyFloat
f_my_f(MyFloat f) -> MyFloat
>>> print (f_defexpr1.__doc__)
f_defexpr1(int x=FLAG1, int y=FLAG2)
>>> print (f_defexpr2.__doc__)
f_defexpr2(int x=FLAG1 | FLAG2, y=FLAG1 & FLAG2)
>>> print (f_defexpr3.__doc__)
f_defexpr3(int x=Ext.CONST1, f=__builtins__.abs)
>>> print (f_defexpr4.__doc__)
f_defexpr4(int x=(Ext.CONST1 + FLAG1) * Ext.CONST2)
"""
"""
cdef
class
Ext
:
cdef
class
Ext
:
...
@@ -159,6 +170,8 @@ cdef class Ext:
...
@@ -159,6 +170,8 @@ cdef class Ext:
cdef
public
list
attr2
cdef
public
list
attr2
cdef
public
Ext
attr3
cdef
public
Ext
attr3
CONST1
,
CONST2
=
1
,
2
def
__init__
(
self
,
a
,
b
,
c
=
None
):
def
__init__
(
self
,
a
,
b
,
c
=
None
):
pass
pass
...
@@ -307,3 +320,19 @@ cpdef MyInt f_my_i(MyInt i):
...
@@ -307,3 +320,19 @@ cpdef MyInt f_my_i(MyInt i):
ctypedef
float
MyFloat
ctypedef
float
MyFloat
cpdef
MyFloat
f_my_f
(
MyFloat
f
):
cpdef
MyFloat
f_my_f
(
MyFloat
f
):
return
f
return
f
cdef
enum
:
FLAG1
FLAG2
cpdef
f_defexpr1
(
int
x
=
FLAG1
,
int
y
=
FLAG2
):
pass
cpdef
f_defexpr2
(
int
x
=
FLAG1
|
FLAG2
,
y
=
FLAG1
&
FLAG2
):
pass
cpdef
f_defexpr3
(
int
x
=
Ext
.
CONST1
,
f
=
__builtins__
.
abs
):
pass
cpdef
f_defexpr4
(
int
x
=
(
Ext
.
CONST1
+
FLAG1
)
*
Ext
.
CONST2
):
pass
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