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
57ea3356
Commit
57ea3356
authored
Sep 10, 2019
by
Jeroen Demeyer
Committed by
T. Wouters
Sep 10, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-37619: update_one_slot() should not ignore wrapper descriptors for wrong type (GH-14836)
parent
f958377b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
6 deletions
+28
-6
Lib/test/test_descr.py
Lib/test/test_descr.py
+12
-0
Misc/NEWS.d/next/Core and Builtins/2019-07-18-11-50-49.bpo-37619.X6Lulo.rst
...ore and Builtins/2019-07-18-11-50-49.bpo-37619.X6Lulo.rst
+3
-0
Objects/typeobject.c
Objects/typeobject.c
+13
-6
No files found.
Lib/test/test_descr.py
View file @
57ea3356
...
...
@@ -4649,6 +4649,18 @@ order (MRO) for bases """
self
.
assertEqual
(
x
[
"y"
],
42
)
self
.
assertEqual
(
x
,
-
x
)
def
test_wrong_class_slot_wrapper
(
self
):
# Check bpo-37619: a wrapper descriptor taken from the wrong class
# should raise an exception instead of silently being ignored
class
A
(
int
):
__eq__
=
str
.
__eq__
__add__
=
str
.
__add__
a
=
A
()
with
self
.
assertRaises
(
TypeError
):
a
==
a
with
self
.
assertRaises
(
TypeError
):
a
+
a
def
test_slot_shadows_class_variable
(
self
):
with
self
.
assertRaises
(
ValueError
)
as
cm
:
class
X
:
...
...
Misc/NEWS.d/next/Core and Builtins/2019-07-18-11-50-49.bpo-37619.X6Lulo.rst
0 → 100644
View file @
57ea3356
When adding a wrapper descriptor from one class to a different class
(for example, setting ``__add__ = str.__add__`` on an ``int`` subclass),
an exception is correctly raised when the operator is called.
Objects/typeobject.c
View file @
57ea3356
...
...
@@ -7307,14 +7307,21 @@ update_one_slot(PyTypeObject *type, slotdef *p)
if
(
tptr
==
NULL
||
tptr
==
ptr
)
generic
=
p
->
function
;
d
=
(
PyWrapperDescrObject
*
)
descr
;
if
(
d
->
d_base
->
wrapper
==
p
->
wrapper
&&
if
((
specific
==
NULL
||
specific
==
d
->
d_wrapped
)
&&
d
->
d_base
->
wrapper
==
p
->
wrapper
&&
PyType_IsSubtype
(
type
,
PyDescr_TYPE
(
d
)))
{
if
(
specific
==
NULL
||
specific
==
d
->
d_wrapped
)
specific
=
d
->
d_wrapped
;
else
use_generic
=
1
;
specific
=
d
->
d_wrapped
;
}
else
{
/* We cannot use the specific slot function because either
- it is not unique: there are multiple methods for this
slot and they conflict
- the signature is wrong (as checked by the ->wrapper
comparison above)
- it's wrapping the wrong class
*/
use_generic
=
1
;
}
}
else
if
(
Py_TYPE
(
descr
)
==
&
PyCFunction_Type
&&
...
...
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