Branch merge
diff --git a/Doc/c-api/module.rst b/Doc/c-api/module.rst
index abac599..649c723 100644
--- a/Doc/c-api/module.rst
+++ b/Doc/c-api/module.rst
@@ -107,7 +107,7 @@
.. cfunction:: int PyModule_AddIntMacro(PyObject *module, macro)
Add an int constant to *module*. The name and the value are taken from
- *macro*. For example ``PyModule_AddConstant(module, AF_INET)`` adds the int
+ *macro*. For example ``PyModule_AddIntMacro(module, AF_INET)`` adds the int
constant *AF_INET* with the value of *AF_INET* to *module*.
Return ``-1`` on error, ``0`` on success.
diff --git a/Doc/includes/email-dir.py b/Doc/includes/email-dir.py
index e67de61..035442b 100644
--- a/Doc/includes/email-dir.py
+++ b/Doc/includes/email-dir.py
@@ -105,7 +105,7 @@
fp.write(composed)
fp.close()
else:
- s = smtplib.SMTP()
+ s = smtplib.SMTP('localhost')
s.sendmail(opts.sender, opts.recipients, composed)
s.quit()
diff --git a/Doc/includes/email-mime.py b/Doc/includes/email-mime.py
index f64df83..7b1c028 100644
--- a/Doc/includes/email-mime.py
+++ b/Doc/includes/email-mime.py
@@ -26,6 +26,6 @@
msg.attach(img)
# Send the email via our own SMTP server.
-s = smtplib.SMTP()
+s = smtplib.SMTP('localhost')
s.sendmail(me, family, msg.as_string())
s.quit()
diff --git a/Doc/includes/email-simple.py b/Doc/includes/email-simple.py
index 689511e..29bd078 100644
--- a/Doc/includes/email-simple.py
+++ b/Doc/includes/email-simple.py
@@ -19,6 +19,6 @@
# Send the message via our own SMTP server, but don't include the
# envelope header.
-s = smtplib.SMTP()
+s = smtplib.SMTP('localhost')
s.sendmail(me, [you], msg.as_string())
s.quit()
diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst
index da5db1d..6449632 100644
--- a/Doc/library/stdtypes.rst
+++ b/Doc/library/stdtypes.rst
@@ -460,6 +460,9 @@
Additional Methods on Integer Types
-----------------------------------
+The integer types implement the :class:`numbers.Integral` :term:`abstract base
+class`. In addition, they provide one more method:
+
.. method:: int.bit_length()
.. method:: long.bit_length()
@@ -491,7 +494,8 @@
Additional Methods on Float
---------------------------
-The float type has some additional methods.
+The float type implements the :class:`numbers.Real` :term:`abstract base
+class`. float also has the following additional methods.
.. method:: float.as_integer_ratio()
diff --git a/Doc/library/sys.rst b/Doc/library/sys.rst
index 1598d96..305d477 100644
--- a/Doc/library/sys.rst
+++ b/Doc/library/sys.rst
@@ -562,10 +562,10 @@
``version_info`` value may be used for a more human-friendly encoding of the
same information.
- The ``hexversion`` is a 32-bit number with the following layout
+ The ``hexversion`` is a 32-bit number with the following layout:
+-------------------------+------------------------------------------------+
- | bits (big endian order) | meaning |
+ | Bits (big endian order) | Meaning |
+=========================+================================================+
| :const:`1-8` | ``PY_MAJOR_VERSION`` (the ``2`` in |
| | ``2.1.0a3``) |
@@ -577,14 +577,14 @@
| | ``2.1.0a3``) |
+-------------------------+------------------------------------------------+
| :const:`25-28` | ``PY_RELEASE_LEVEL`` (``0xA`` for alpha, |
- | | ``0xB`` for beta, ``0xC`` for gamma and |
- | | ``0xF`` for final) |
+ | | ``0xB`` for beta, ``0xC`` for release |
+ | | candidate and ``0xF`` for final) |
+-------------------------+------------------------------------------------+
| :const:`29-32` | ``PY_RELEASE_SERIAL`` (the ``3`` in |
- | | ``2.1.0a3``) |
+ | | ``2.1.0a3``, zero for final releases) |
+-------------------------+------------------------------------------------+
- thus ``2.1.0a3`` is hexversion ``0x020100a3``
+ Thus ``2.1.0a3`` is hexversion ``0x020100a3``.
.. versionadded:: 1.5.2
@@ -595,7 +595,7 @@
internal representation of integers. The attributes are read only.
+-------------------------+----------------------------------------------+
- | attribute | explanation |
+ | Attribute | Explanation |
+=========================+==============================================+
| :const:`bits_per_digit` | number of bits held in each digit. Python |
| | integers are stored internally in base |
diff --git a/Doc/tutorial/classes.rst b/Doc/tutorial/classes.rst
index ed0e655..5ee9067 100644
--- a/Doc/tutorial/classes.rst
+++ b/Doc/tutorial/classes.rst
@@ -687,7 +687,6 @@
>>> it.next()
'c'
>>> it.next()
-
Traceback (most recent call last):
File "<stdin>", line 1, in ?
it.next()
@@ -699,7 +698,7 @@
:meth:`next`, then :meth:`__iter__` can just return ``self``::
class Reverse:
- "Iterator for looping over a sequence backwards"
+ """Iterator for looping over a sequence backwards."""
def __init__(self, data):
self.data = data
self.index = len(data)
@@ -711,6 +710,8 @@
self.index = self.index - 1
return self.data[self.index]
+::
+
>>> rev = Reverse('spam')
>>> iter(rev)
<__main__.Reverse object at 0x00A1DB50>
@@ -739,6 +740,8 @@
for index in range(len(data)-1, -1, -1):
yield data[index]
+::
+
>>> for char in reverse('golf'):
... print char
...
diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py
index b5e86fb..1fe0de5 100644
--- a/Lib/test/test_descr.py
+++ b/Lib/test/test_descr.py
@@ -4564,6 +4564,22 @@
with self.assertRaises(AttributeError):
del X.__abstractmethods__
+ def test_proxy_call(self):
+ class FakeStr(object):
+ __class__ = str
+
+ fake_str = FakeStr()
+ # isinstance() reads __class__ on new style classes
+ self.assertTrue(isinstance(fake_str, str))
+
+ # call a method descriptor
+ with self.assertRaises(TypeError):
+ str.split(fake_str)
+
+ # call a slot wrapper descriptor
+ with self.assertRaises(TypeError):
+ str.__add__(fake_str, "abc")
+
class DictProxyTests(unittest.TestCase):
def setUp(self):
diff --git a/Misc/ACKS b/Misc/ACKS
index 450a3a5..3c0e370 100644
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -780,6 +780,7 @@
Patrick Strawderman
Dan Stromberg
Daniel Stutzbach
+Andreas Stührk
Nathan Sullivan
Mark Summerfield
Hisao Suzuki
diff --git a/Misc/NEWS b/Misc/NEWS
index bb6f5ef..0030bab 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -9,6 +9,11 @@
Core and Builtins
-----------------
+- Issue #9756: When calling a method descriptor or a slot wrapper descriptor,
+ the check of the object type doesn't read the __class__ attribute anymore.
+ Fix a crash if a class override its __class__ attribute (e.g. a proxy of the
+ str type). Patch written by Andreas Stührk.
+
- Issue #10517: After fork(), reinitialize the TLS used by the PyGILState_*
APIs, to avoid a crash with the pthread implementation in RHEL 5. Patch
by Charles-François Natali.
diff --git a/Misc/python.man b/Misc/python.man
index ddfccef..9308787 100644
--- a/Misc/python.man
+++ b/Misc/python.man
@@ -31,7 +31,7 @@
.B \-O
]
[
-.B \-O0
+.B \-OO
]
[
.B -Q
@@ -148,7 +148,7 @@
.I .pyc
to \fI.pyo\fP. Given twice, causes docstrings to be discarded.
.TP
-.B \-O0
+.B \-OO
Discard docstrings in addition to the \fB-O\fP optimizations.
.TP
.BI "\-Q " argument
diff --git a/Objects/descrobject.c b/Objects/descrobject.c
index 9d735a2..135b6d2 100644
--- a/Objects/descrobject.c
+++ b/Objects/descrobject.c
@@ -224,7 +224,8 @@
return NULL;
}
self = PyTuple_GET_ITEM(args, 0);
- if (!PyObject_IsInstance(self, (PyObject *)(descr->d_type))) {
+ if (!_PyObject_RealIsSubclass((PyObject *)Py_TYPE(self),
+ (PyObject *)(descr->d_type))) {
PyErr_Format(PyExc_TypeError,
"descriptor '%.200s' "
"requires a '%.100s' object "
@@ -282,7 +283,8 @@
return NULL;
}
self = PyTuple_GET_ITEM(args, 0);
- if (!PyObject_IsInstance(self, (PyObject *)(descr->d_type))) {
+ if (!_PyObject_RealIsSubclass((PyObject *)Py_TYPE(self),
+ (PyObject *)(descr->d_type))) {
PyErr_Format(PyExc_TypeError,
"descriptor '%.200s' "
"requires a '%.100s' object "
@@ -1046,7 +1048,8 @@
assert(PyObject_TypeCheck(d, &PyWrapperDescr_Type));
descr = (PyWrapperDescrObject *)d;
- assert(PyObject_IsInstance(self, (PyObject *)(descr->d_type)));
+ assert(_PyObject_RealIsSubclass((PyObject *)Py_TYPE(self),
+ (PyObject *)(descr->d_type)));
wp = PyObject_GC_New(wrapperobject, &wrappertype);
if (wp != NULL) {