Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
021bb878
Commit
021bb878
authored
Jan 24, 2014
by
Zachary Ware
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #20381: Fix sanity checking on default arguments when c_default is
also specified.
parent
66964cd4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
3 deletions
+16
-3
Misc/NEWS
Misc/NEWS
+5
-0
Tools/clinic/clinic.py
Tools/clinic/clinic.py
+11
-3
No files found.
Misc/NEWS
View file @
021bb878
...
...
@@ -141,6 +141,11 @@ Tests
Tools/Demos
-----------
- Issue #20381: Argument Clinic now sanity checks the default argument when
c_default is also specified, providing a nice failure message for
disallowed values.
- Issue #20189: Argument Clinic now ensures that parser functions for
__new__ are always of type newfunc, the type of the tp_new slot.
Similarly, parser functions for __init__ are now always of type initproc,
...
...
Tools/clinic/clinic.py
View file @
021bb878
...
...
@@ -3279,11 +3279,11 @@ class DSLParser:
fail
(
"You can't specify py_default without specifying a default value!"
)
else
:
default
=
default
.
strip
()
bad
=
False
ast_input
=
"x = {}"
.
format
(
default
)
try
:
module
=
ast
.
parse
(
ast_input
)
bad
=
False
if
'c_default'
not
in
kwargs
:
# we can only represent very simple data values in C.
# detect whether default is okay, via a blacklist
...
...
@@ -3317,8 +3317,16 @@ class DSLParser:
bad
=
blacklist
.
bad
else
:
# if they specify a c_default, we can be more lenient about the default value.
# but at least ensure that we can turn it into text and reconstitute it correctly.
bad
=
default
!=
repr
(
eval
(
default
))
# but at least make an attempt at ensuring it's a valid expression.
try
:
value
=
eval
(
default
)
if
value
==
unspecified
:
fail
(
"'unspecified' is not a legal default value!"
)
except
NameError
:
pass
# probably a named constant
except
Exception
as
e
:
fail
(
"Malformed expression given as default value
\
n
"
"{!r} caused {!r}"
.
format
(
default
,
e
))
if
bad
:
fail
(
"Unsupported expression as default value: "
+
repr
(
default
))
...
...
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