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
5334bcdf
Commit
5334bcdf
authored
Jan 31, 2014
by
Yury Selivanov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
inspect.Signauture.from_function: validate duck functions in Signature constructor #17159
parent
63da7c7b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
5 deletions
+11
-5
Lib/inspect.py
Lib/inspect.py
+11
-5
No files found.
Lib/inspect.py
View file @
5334bcdf
...
...
@@ -2097,10 +2097,14 @@ class Signature:
def
from_function
(
cls
,
func
):
'''Constructs Signature for the given python function'''
if
not
(
isfunction
(
func
)
or
_signature_is_functionlike
(
func
)):
# If it's not a pure Python function, and not a duck type
# of pure function:
raise
TypeError
(
'{!r} is not a Python function'
.
format
(
func
))
is_duck_function
=
False
if
not
isfunction
(
func
):
if
_signature_is_functionlike
(
func
):
is_duck_function
=
True
else
:
# If it's not a pure Python function, and not a duck type
# of pure function:
raise
TypeError
(
'{!r} is not a Python function'
.
format
(
func
))
Parameter
=
cls
.
_parameter_cls
...
...
@@ -2164,9 +2168,11 @@ class Signature:
parameters
.
append
(
Parameter
(
name
,
annotation
=
annotation
,
kind
=
_VAR_KEYWORD
))
# Is 'func' is a pure Python function - don't validate the
# parameters list (for correct order and defaults), it should be OK.
return
cls
(
parameters
,
return_annotation
=
annotations
.
get
(
'return'
,
_empty
),
__validate_parameters__
=
False
)
__validate_parameters__
=
is_duck_function
)
@
classmethod
def
from_builtin
(
cls
,
func
):
...
...
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