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
0207e769
Commit
0207e769
authored
Apr 23, 2016
by
Serhiy Storchaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #26822: itemgetter, attrgetter and methodcaller objects no longer
silently ignore keyword arguments.
parent
bca06ccb
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
0 deletions
+18
-0
Lib/test/test_operator.py
Lib/test/test_operator.py
+9
-0
Misc/NEWS
Misc/NEWS
+3
-0
Modules/operator.c
Modules/operator.c
+6
-0
No files found.
Lib/test/test_operator.py
View file @
0207e769
...
...
@@ -371,6 +371,9 @@ class OperatorTestCase(unittest.TestCase):
a
.
name
=
'arthur'
f
=
operator
.
attrgetter
(
'name'
)
self
.
assertEqual
(
f
(
a
),
'arthur'
)
self
.
assertRaises
(
TypeError
,
f
)
self
.
assertRaises
(
TypeError
,
f
,
a
,
'dent'
)
self
.
assertRaises
(
TypeError
,
f
,
a
,
surname
=
'dent'
)
f
=
operator
.
attrgetter
(
'rank'
)
self
.
assertRaises
(
AttributeError
,
f
,
a
)
f
=
operator
.
attrgetter
(
2
)
...
...
@@ -414,6 +417,9 @@ class OperatorTestCase(unittest.TestCase):
a
=
'ABCDE'
f
=
operator
.
itemgetter
(
2
)
self
.
assertEqual
(
f
(
a
),
'C'
)
self
.
assertRaises
(
TypeError
,
f
)
self
.
assertRaises
(
TypeError
,
f
,
a
,
3
)
self
.
assertRaises
(
TypeError
,
f
,
a
,
size
=
3
)
f
=
operator
.
itemgetter
(
10
)
self
.
assertRaises
(
IndexError
,
f
,
a
)
...
...
@@ -456,6 +462,9 @@ class OperatorTestCase(unittest.TestCase):
self
.
assertRaises
(
IndexError
,
f
,
a
)
f
=
operator
.
methodcaller
(
'foo'
,
1
,
2
)
self
.
assertEqual
(
f
(
a
),
3
)
self
.
assertRaises
(
TypeError
,
f
)
self
.
assertRaises
(
TypeError
,
f
,
a
,
3
)
self
.
assertRaises
(
TypeError
,
f
,
a
,
spam
=
3
)
f
=
operator
.
methodcaller
(
'bar'
)
self
.
assertEqual
(
f
(
a
),
42
)
self
.
assertRaises
(
TypeError
,
f
,
a
,
a
)
...
...
Misc/NEWS
View file @
0207e769
...
...
@@ -77,6 +77,9 @@ Core and Builtins
Library
-------
-
Issue
#
26822
:
itemgetter
,
attrgetter
and
methodcaller
objects
no
longer
silently
ignore
keyword
arguments
.
-
Issue
#
26657
:
Fix
directory
traversal
vulnerability
with
SimpleHTTPServer
on
Windows
.
This
fixes
a
regression
that
was
introduced
in
2.7.7
.
Based
on
patch
by
Philipp
Hagemeister
.
...
...
Modules/operator.c
View file @
0207e769
...
...
@@ -511,6 +511,8 @@ itemgetter_call(itemgetterobject *ig, PyObject *args, PyObject *kw)
PyObject
*
obj
,
*
result
;
Py_ssize_t
i
,
nitems
=
ig
->
nitems
;
if
(
!
_PyArg_NoKeywords
(
"itemgetter"
,
kw
))
return
NULL
;
if
(
!
PyArg_UnpackTuple
(
args
,
"itemgetter"
,
1
,
1
,
&
obj
))
return
NULL
;
if
(
nitems
==
1
)
...
...
@@ -691,6 +693,8 @@ attrgetter_call(attrgetterobject *ag, PyObject *args, PyObject *kw)
PyObject
*
obj
,
*
result
;
Py_ssize_t
i
,
nattrs
=
ag
->
nattrs
;
if
(
!
_PyArg_NoKeywords
(
"attrgetter"
,
kw
))
return
NULL
;
if
(
!
PyArg_UnpackTuple
(
args
,
"attrgetter"
,
1
,
1
,
&
obj
))
return
NULL
;
if
(
ag
->
nattrs
==
1
)
...
...
@@ -838,6 +842,8 @@ methodcaller_call(methodcallerobject *mc, PyObject *args, PyObject *kw)
{
PyObject
*
method
,
*
obj
,
*
result
;
if
(
!
_PyArg_NoKeywords
(
"methodcaller"
,
kw
))
return
NULL
;
if
(
!
PyArg_UnpackTuple
(
args
,
"methodcaller"
,
1
,
1
,
&
obj
))
return
NULL
;
method
=
PyObject_GetAttr
(
obj
,
mc
->
name
);
...
...
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