mirror of
https://github.com/python/cpython.git
synced 2025-09-30 20:31:52 +00:00
Merge.
This commit is contained in:
commit
04fb08f690
6 changed files with 47 additions and 77 deletions
|
@ -772,21 +772,6 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
|
||||||
|
|
||||||
PyAPI_FUNC(Py_ssize_t) PyNumber_AsSsize_t(PyObject *o, PyObject *exc);
|
PyAPI_FUNC(Py_ssize_t) PyNumber_AsSsize_t(PyObject *o, PyObject *exc);
|
||||||
|
|
||||||
/*
|
|
||||||
Returns the Integral instance converted to an int. The
|
|
||||||
instance is expected to be int or long or have an __int__
|
|
||||||
method. Steals integral's reference. error_format will be
|
|
||||||
used to create the TypeError if integral isn't actually an
|
|
||||||
Integral instance. error_format should be a format string
|
|
||||||
that can accept a char* naming integral's type.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef Py_LIMITED_API
|
|
||||||
PyAPI_FUNC(PyObject *) _PyNumber_ConvertIntegralToInt(
|
|
||||||
PyObject *integral,
|
|
||||||
const char* error_format);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Returns the object converted to Py_ssize_t by going through
|
Returns the object converted to Py_ssize_t by going through
|
||||||
PyNumber_Index first. If an overflow error occurs while
|
PyNumber_Index first. If an overflow error occurs while
|
||||||
|
|
|
@ -2267,7 +2267,8 @@ class DocTestCase(unittest.TestCase):
|
||||||
return "Doctest: " + self._dt_test.name
|
return "Doctest: " + self._dt_test.name
|
||||||
|
|
||||||
class SkipDocTestCase(DocTestCase):
|
class SkipDocTestCase(DocTestCase):
|
||||||
def __init__(self):
|
def __init__(self, module):
|
||||||
|
self.module = module
|
||||||
DocTestCase.__init__(self, None)
|
DocTestCase.__init__(self, None)
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
@ -2277,7 +2278,10 @@ class SkipDocTestCase(DocTestCase):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def shortDescription(self):
|
def shortDescription(self):
|
||||||
return "Skipping tests from %s" % module.__name__
|
return "Skipping tests from %s" % self.module.__name__
|
||||||
|
|
||||||
|
__str__ = shortDescription
|
||||||
|
|
||||||
|
|
||||||
def DocTestSuite(module=None, globs=None, extraglobs=None, test_finder=None,
|
def DocTestSuite(module=None, globs=None, extraglobs=None, test_finder=None,
|
||||||
**options):
|
**options):
|
||||||
|
@ -2325,7 +2329,7 @@ def DocTestSuite(module=None, globs=None, extraglobs=None, test_finder=None,
|
||||||
if not tests and sys.flags.optimize >=2:
|
if not tests and sys.flags.optimize >=2:
|
||||||
# Skip doctests when running with -O2
|
# Skip doctests when running with -O2
|
||||||
suite = unittest.TestSuite()
|
suite = unittest.TestSuite()
|
||||||
suite.addTest(SkipDocTestCase())
|
suite.addTest(SkipDocTestCase(module))
|
||||||
return suite
|
return suite
|
||||||
elif not tests:
|
elif not tests:
|
||||||
# Why do we want to do this? Because it reveals a bug that might
|
# Why do we want to do this? Because it reveals a bug that might
|
||||||
|
|
|
@ -1770,6 +1770,7 @@ order (MRO) for bases """
|
||||||
("__format__", format, format_impl, set(), {}),
|
("__format__", format, format_impl, set(), {}),
|
||||||
("__floor__", math.floor, zero, set(), {}),
|
("__floor__", math.floor, zero, set(), {}),
|
||||||
("__trunc__", math.trunc, zero, set(), {}),
|
("__trunc__", math.trunc, zero, set(), {}),
|
||||||
|
("__trunc__", int, zero, set(), {}),
|
||||||
("__ceil__", math.ceil, zero, set(), {}),
|
("__ceil__", math.ceil, zero, set(), {}),
|
||||||
("__dir__", dir, empty_seq, set(), {}),
|
("__dir__", dir, empty_seq, set(), {}),
|
||||||
]
|
]
|
||||||
|
|
|
@ -30,6 +30,9 @@ Core and Builtins
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Issue #12757: Fix the skipping of doctests when python is run with -OO so
|
||||||
|
that it works in unittest's verbose mode as well as non-verbose mode.
|
||||||
|
|
||||||
- Issue #7652: Integrate the decimal floating point libmpdec library to speed
|
- Issue #7652: Integrate the decimal floating point libmpdec library to speed
|
||||||
up the decimal module. Performance gains of the new C implementation are
|
up the decimal module. Performance gains of the new C implementation are
|
||||||
between 12x and 80x, depending on the application.
|
between 12x and 80x, depending on the application.
|
||||||
|
|
|
@ -1268,37 +1268,32 @@ PyNumber_AsSsize_t(PyObject *item, PyObject *err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PyObject *
|
/*
|
||||||
_PyNumber_ConvertIntegralToInt(PyObject *integral, const char* error_format)
|
Returns the Integral instance converted to an int. The instance is expected
|
||||||
|
to be an int or have an __int__ method. Steals integral's
|
||||||
|
reference. error_format will be used to create the TypeError if integral
|
||||||
|
isn't actually an Integral instance. error_format should be a format string
|
||||||
|
that can accept a char* naming integral's type.
|
||||||
|
*/
|
||||||
|
static PyObject *
|
||||||
|
convert_integral_to_int(PyObject *integral, const char *error_format)
|
||||||
{
|
{
|
||||||
static PyObject *int_name = NULL;
|
PyNumberMethods *nb;
|
||||||
if (int_name == NULL) {
|
if (PyLong_Check(integral))
|
||||||
int_name = PyUnicode_InternFromString("__int__");
|
return integral;
|
||||||
if (int_name == NULL)
|
nb = Py_TYPE(integral)->tp_as_number;
|
||||||
return NULL;
|
if (nb->nb_int) {
|
||||||
}
|
PyObject *as_int = nb->nb_int(integral);
|
||||||
|
|
||||||
if (integral && !PyLong_Check(integral)) {
|
|
||||||
/* Don't go through tp_as_number->nb_int to avoid
|
|
||||||
hitting the classic class fallback to __trunc__. */
|
|
||||||
PyObject *int_func = PyObject_GetAttr(integral, int_name);
|
|
||||||
if (int_func == NULL) {
|
|
||||||
PyErr_Clear(); /* Raise a different error. */
|
|
||||||
goto non_integral_error;
|
|
||||||
}
|
|
||||||
Py_DECREF(integral);
|
Py_DECREF(integral);
|
||||||
integral = PyEval_CallObject(int_func, NULL);
|
if (!as_int)
|
||||||
Py_DECREF(int_func);
|
return NULL;
|
||||||
if (integral && !PyLong_Check(integral)) {
|
if (PyLong_Check(as_int))
|
||||||
goto non_integral_error;
|
return as_int;
|
||||||
}
|
Py_DECREF(as_int);
|
||||||
}
|
}
|
||||||
return integral;
|
|
||||||
|
|
||||||
non_integral_error:
|
|
||||||
PyErr_Format(PyExc_TypeError, error_format, Py_TYPE(integral)->tp_name);
|
PyErr_Format(PyExc_TypeError, error_format, Py_TYPE(integral)->tp_name);
|
||||||
Py_DECREF(integral);
|
Py_DECREF(integral);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1325,16 +1320,10 @@ PyObject *
|
||||||
PyNumber_Long(PyObject *o)
|
PyNumber_Long(PyObject *o)
|
||||||
{
|
{
|
||||||
PyNumberMethods *m;
|
PyNumberMethods *m;
|
||||||
static PyObject *trunc_name = NULL;
|
|
||||||
PyObject *trunc_func;
|
PyObject *trunc_func;
|
||||||
const char *buffer;
|
const char *buffer;
|
||||||
Py_ssize_t buffer_len;
|
Py_ssize_t buffer_len;
|
||||||
|
_Py_IDENTIFIER(__trunc__);
|
||||||
if (trunc_name == NULL) {
|
|
||||||
trunc_name = PyUnicode_InternFromString("__trunc__");
|
|
||||||
if (trunc_name == NULL)
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (o == NULL)
|
if (o == NULL)
|
||||||
return null_error();
|
return null_error();
|
||||||
|
@ -1356,23 +1345,23 @@ PyNumber_Long(PyObject *o)
|
||||||
}
|
}
|
||||||
if (PyLong_Check(o)) /* An int subclass without nb_int */
|
if (PyLong_Check(o)) /* An int subclass without nb_int */
|
||||||
return _PyLong_Copy((PyLongObject *)o);
|
return _PyLong_Copy((PyLongObject *)o);
|
||||||
trunc_func = PyObject_GetAttr(o, trunc_name);
|
trunc_func = _PyObject_LookupSpecial(o, &PyId___trunc__);
|
||||||
if (trunc_func) {
|
if (trunc_func) {
|
||||||
PyObject *truncated = PyEval_CallObject(trunc_func, NULL);
|
PyObject *truncated = PyEval_CallObject(trunc_func, NULL);
|
||||||
PyObject *int_instance;
|
PyObject *int_instance;
|
||||||
Py_DECREF(trunc_func);
|
Py_DECREF(trunc_func);
|
||||||
/* __trunc__ is specified to return an Integral type,
|
/* __trunc__ is specified to return an Integral type,
|
||||||
but long() needs to return a long. */
|
but int() needs to return a int. */
|
||||||
int_instance = _PyNumber_ConvertIntegralToInt(
|
int_instance = convert_integral_to_int(truncated,
|
||||||
truncated,
|
|
||||||
"__trunc__ returned non-Integral (type %.200s)");
|
"__trunc__ returned non-Integral (type %.200s)");
|
||||||
return int_instance;
|
return int_instance;
|
||||||
}
|
}
|
||||||
PyErr_Clear(); /* It's not an error if o.__trunc__ doesn't exist. */
|
if (PyErr_Occurred())
|
||||||
|
return NULL;
|
||||||
|
|
||||||
if (PyBytes_Check(o))
|
if (PyBytes_Check(o))
|
||||||
/* need to do extra error checking that PyLong_FromString()
|
/* need to do extra error checking that PyLong_FromString()
|
||||||
* doesn't do. In particular long('9.5') must raise an
|
* doesn't do. In particular int('9.5') must raise an
|
||||||
* exception, not truncate the float.
|
* exception, not truncate the float.
|
||||||
*/
|
*/
|
||||||
return long_from_string(PyBytes_AS_STRING(o),
|
return long_from_string(PyBytes_AS_STRING(o),
|
||||||
|
@ -2411,10 +2400,8 @@ PyObject_CallFunctionObjArgs(PyObject *callable, ...)
|
||||||
|
|
||||||
/* isinstance(), issubclass() */
|
/* isinstance(), issubclass() */
|
||||||
|
|
||||||
/* abstract_get_bases() has logically 4 return states, with a sort of 0th
|
/* abstract_get_bases() has logically 4 return states:
|
||||||
* state that will almost never happen.
|
|
||||||
*
|
*
|
||||||
* 0. creating the __bases__ static string could get a MemoryError
|
|
||||||
* 1. getattr(cls, '__bases__') could raise an AttributeError
|
* 1. getattr(cls, '__bases__') could raise an AttributeError
|
||||||
* 2. getattr(cls, '__bases__') could raise some other exception
|
* 2. getattr(cls, '__bases__') could raise some other exception
|
||||||
* 3. getattr(cls, '__bases__') could return a tuple
|
* 3. getattr(cls, '__bases__') could return a tuple
|
||||||
|
@ -2440,16 +2427,11 @@ PyObject_CallFunctionObjArgs(PyObject *callable, ...)
|
||||||
static PyObject *
|
static PyObject *
|
||||||
abstract_get_bases(PyObject *cls)
|
abstract_get_bases(PyObject *cls)
|
||||||
{
|
{
|
||||||
static PyObject *__bases__ = NULL;
|
_Py_IDENTIFIER(__bases__);
|
||||||
PyObject *bases;
|
PyObject *bases;
|
||||||
|
|
||||||
if (__bases__ == NULL) {
|
|
||||||
__bases__ = PyUnicode_InternFromString("__bases__");
|
|
||||||
if (__bases__ == NULL)
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
Py_ALLOW_RECURSION
|
Py_ALLOW_RECURSION
|
||||||
bases = PyObject_GetAttr(cls, __bases__);
|
bases = _PyObject_GetAttrId(cls, &PyId___bases__);
|
||||||
Py_END_ALLOW_RECURSION
|
Py_END_ALLOW_RECURSION
|
||||||
if (bases == NULL) {
|
if (bases == NULL) {
|
||||||
if (PyErr_ExceptionMatches(PyExc_AttributeError))
|
if (PyErr_ExceptionMatches(PyExc_AttributeError))
|
||||||
|
@ -2519,19 +2501,13 @@ static int
|
||||||
recursive_isinstance(PyObject *inst, PyObject *cls)
|
recursive_isinstance(PyObject *inst, PyObject *cls)
|
||||||
{
|
{
|
||||||
PyObject *icls;
|
PyObject *icls;
|
||||||
static PyObject *__class__ = NULL;
|
|
||||||
int retval = 0;
|
int retval = 0;
|
||||||
|
_Py_IDENTIFIER(__class__);
|
||||||
if (__class__ == NULL) {
|
|
||||||
__class__ = PyUnicode_InternFromString("__class__");
|
|
||||||
if (__class__ == NULL)
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (PyType_Check(cls)) {
|
if (PyType_Check(cls)) {
|
||||||
retval = PyObject_TypeCheck(inst, (PyTypeObject *)cls);
|
retval = PyObject_TypeCheck(inst, (PyTypeObject *)cls);
|
||||||
if (retval == 0) {
|
if (retval == 0) {
|
||||||
PyObject *c = PyObject_GetAttr(inst, __class__);
|
PyObject *c = _PyObject_GetAttrId(inst, &PyId___class__);
|
||||||
if (c == NULL) {
|
if (c == NULL) {
|
||||||
if (PyErr_ExceptionMatches(PyExc_AttributeError))
|
if (PyErr_ExceptionMatches(PyExc_AttributeError))
|
||||||
PyErr_Clear();
|
PyErr_Clear();
|
||||||
|
@ -2552,7 +2528,7 @@ recursive_isinstance(PyObject *inst, PyObject *cls)
|
||||||
if (!check_class(cls,
|
if (!check_class(cls,
|
||||||
"isinstance() arg 2 must be a type or tuple of types"))
|
"isinstance() arg 2 must be a type or tuple of types"))
|
||||||
return -1;
|
return -1;
|
||||||
icls = PyObject_GetAttr(inst, __class__);
|
icls = _PyObject_GetAttrId(inst, &PyId___class__);
|
||||||
if (icls == NULL) {
|
if (icls == NULL) {
|
||||||
if (PyErr_ExceptionMatches(PyExc_AttributeError))
|
if (PyErr_ExceptionMatches(PyExc_AttributeError))
|
||||||
PyErr_Clear();
|
PyErr_Clear();
|
||||||
|
|
|
@ -1837,10 +1837,11 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
|
||||||
if (PyGen_CheckExact(x)) {
|
if (PyGen_CheckExact(x)) {
|
||||||
retval = _PyGen_Send((PyGenObject *)x, u);
|
retval = _PyGen_Send((PyGenObject *)x, u);
|
||||||
} else {
|
} else {
|
||||||
|
_Py_IDENTIFIER(send);
|
||||||
if (u == Py_None)
|
if (u == Py_None)
|
||||||
retval = PyIter_Next(x);
|
retval = PyIter_Next(x);
|
||||||
else
|
else
|
||||||
retval = PyObject_CallMethod(x, "send", "O", u);
|
retval = _PyObject_CallMethodId(x, &PyId_send, "O", u);
|
||||||
}
|
}
|
||||||
Py_DECREF(u);
|
Py_DECREF(u);
|
||||||
if (!retval) {
|
if (!retval) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue