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
bd41d1b1
Commit
bd41d1b1
authored
Jan 29, 2013
by
Antoine Pitrou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #17071: Signature.bind() now works when one of the keyword arguments is named ``self``.
parent
c5b75db5
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
4 deletions
+17
-4
Lib/inspect.py
Lib/inspect.py
+4
-4
Lib/test/test_inspect.py
Lib/test/test_inspect.py
+10
-0
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Lib/inspect.py
View file @
bd41d1b1
...
...
@@ -2028,19 +2028,19 @@ class Signature:
return
self
.
_bound_arguments_cls
(
self
,
arguments
)
def
bind
(
self
,
*
args
,
**
kwargs
):
def
bind
(
__bind_
self
,
*
args
,
**
kwargs
):
'''Get a BoundArguments object, that maps the passed `args`
and `kwargs` to the function's signature. Raises `TypeError`
if the passed arguments can not be bound.
'''
return
self
.
_bind
(
args
,
kwargs
)
return
__bind_
self
.
_bind
(
args
,
kwargs
)
def
bind_partial
(
self
,
*
args
,
**
kwargs
):
def
bind_partial
(
__bind_
self
,
*
args
,
**
kwargs
):
'''Get a BoundArguments object, that partially maps the
passed `args` and `kwargs` to the function's signature.
Raises `TypeError` if the passed arguments can not be bound.
'''
return
self
.
_bind
(
args
,
kwargs
,
partial
=
True
)
return
__bind_
self
.
_bind
(
args
,
kwargs
,
partial
=
True
)
def
__str__
(
self
):
result
=
[]
...
...
Lib/test/test_inspect.py
View file @
bd41d1b1
...
...
@@ -2241,6 +2241,16 @@ class TestSignatureBind(unittest.TestCase):
with
self
.
assertRaisesRegex
(
TypeError
,
"parameter is positional only"
):
self
.
call
(
test
,
a_po
=
1
,
b_po
=
2
)
def
test_signature_bind_with_self_arg
(
self
):
# Issue #17071: one of the parameters is named "self
def
test
(
a
,
self
,
b
):
pass
sig
=
inspect
.
signature
(
test
)
ba
=
sig
.
bind
(
1
,
2
,
3
)
self
.
assertEqual
(
ba
.
args
,
(
1
,
2
,
3
))
ba
=
sig
.
bind
(
1
,
self
=
2
,
b
=
3
)
self
.
assertEqual
(
ba
.
args
,
(
1
,
2
,
3
))
class
TestBoundArguments
(
unittest
.
TestCase
):
def
test_signature_bound_arguments_unhashable
(
self
):
...
...
Misc/NEWS
View file @
bd41d1b1
...
...
@@ -164,6 +164,9 @@ Core and Builtins
Library
-------
- Issue #17071: Signature.bind() now works when one of the keyword arguments
is named ``self``.
- Issue #12004: Fix an internal error in PyZipFile when writing an invalid
Python file. Patch by Ben Morgan.
...
...
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