summaryrefslogtreecommitdiffstats
path: root/Objects/floatobject.c
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2022-02-25 23:53:27 (GMT)
committerGitHub <noreply@github.com>2022-02-25 23:53:27 (GMT)
commit5ab745fc51e159ead28b523414e52f0bcc1ef353 (patch)
tree02cb9106f63ae34f86803f92b604587abd359314 /Objects/floatobject.c
parent4060111f9dc44682f9d7bdafb4e7dacb96706ad3 (diff)
downloadcpython-5ab745fc51e159ead28b523414e52f0bcc1ef353.zip
cpython-5ab745fc51e159ead28b523414e52f0bcc1ef353.tar.gz
cpython-5ab745fc51e159ead28b523414e52f0bcc1ef353.tar.bz2
bpo-46852: Remove the float.__set_format__() method (GH-31585)
Remove the undocumented private float.__set_format__() method, previously known as float.__set_format__() in Python 3.7. Its docstring said: "You probably don't want to use this function. It exists mainly to be used in Python's test suite."
Diffstat (limited to 'Objects/floatobject.c')
-rw-r--r--Objects/floatobject.c76
1 files changed, 2 insertions, 74 deletions
diff --git a/Objects/floatobject.c b/Objects/floatobject.c
index 342e768..91ca848 100644
--- a/Objects/floatobject.c
+++ b/Objects/floatobject.c
@@ -1708,7 +1708,6 @@ typedef enum {
} float_format_type;
static float_format_type double_format, float_format;
-static float_format_type detected_double_format, detected_float_format;
/*[clinic input]
@classmethod
@@ -1760,78 +1759,6 @@ float___getformat___impl(PyTypeObject *type, const char *typestr)
}
}
-/*[clinic input]
-@classmethod
-float.__setformat__
-
- typestr: str
- Must be 'double' or 'float'.
- fmt: str
- Must be one of 'unknown', 'IEEE, big-endian' or 'IEEE, little-endian',
- and in addition can only be one of the latter two if it appears to
- match the underlying C reality.
- /
-
-You probably don't want to use this function.
-
-It exists mainly to be used in Python's test suite.
-
-Override the automatic determination of C-level floating point type.
-This affects how floats are converted to and from binary strings.
-[clinic start generated code]*/
-
-static PyObject *
-float___setformat___impl(PyTypeObject *type, const char *typestr,
- const char *fmt)
-/*[clinic end generated code: output=06864de1fb5f1f04 input=c0e9e04dd87f9988]*/
-{
- float_format_type f;
- float_format_type detected;
- float_format_type *p;
-
- if (strcmp(typestr, "double") == 0) {
- p = &double_format;
- detected = detected_double_format;
- }
- else if (strcmp(typestr, "float") == 0) {
- p = &float_format;
- detected = detected_float_format;
- }
- else {
- PyErr_SetString(PyExc_ValueError,
- "__setformat__() argument 1 must "
- "be 'double' or 'float'");
- return NULL;
- }
-
- if (strcmp(fmt, "unknown") == 0) {
- f = unknown_format;
- }
- else if (strcmp(fmt, "IEEE, little-endian") == 0) {
- f = ieee_little_endian_format;
- }
- else if (strcmp(fmt, "IEEE, big-endian") == 0) {
- f = ieee_big_endian_format;
- }
- else {
- PyErr_SetString(PyExc_ValueError,
- "__setformat__() argument 2 must be "
- "'unknown', 'IEEE, little-endian' or "
- "'IEEE, big-endian'");
- return NULL;
-
- }
-
- if (f != unknown_format && f != detected) {
- PyErr_Format(PyExc_ValueError,
- "can only set %s format to 'unknown' or the "
- "detected platform value", typestr);
- return NULL;
- }
-
- *p = f;
- Py_RETURN_NONE;
-}
static PyObject *
float_getreal(PyObject *v, void *closure)
@@ -1885,7 +1812,6 @@ static PyMethodDef float_methods[] = {
FLOAT_IS_INTEGER_METHODDEF
FLOAT___GETNEWARGS___METHODDEF
FLOAT___GETFORMAT___METHODDEF
- FLOAT___SETFORMAT___METHODDEF
FLOAT___FORMAT___METHODDEF
{NULL, NULL} /* sentinel */
};
@@ -1989,6 +1915,8 @@ _PyFloat_InitState(PyInterpreterState *interp)
return;
}
+ float_format_type detected_double_format, detected_float_format;
+
/* We attempt to determine if this machine is using IEEE
floating point formats by peering at the bits of some
carefully chosen values. If it looks like we are on an