summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2001-12-06 06:23:26 (GMT)
committerTim Peters <tim.peters@gmail.com>2001-12-06 06:23:26 (GMT)
commit3caca2326e04ea3c0d1f8c6a588e646d8201af38 (patch)
tree8a1763afce3137836cd61eecf3b049b354f37462 /Python
parente50959a58ef4f365295f0393cb980de890c0024a (diff)
downloadcpython-3caca2326e04ea3c0d1f8c6a588e646d8201af38.zip
cpython-3caca2326e04ea3c0d1f8c6a588e646d8201af38.tar.gz
cpython-3caca2326e04ea3c0d1f8c6a588e646d8201af38.tar.bz2
SF bug #488514: -Qnew needs work
Big Hammer to implement -Qnew as PEP 238 says it should work (a global option affecting all instances of "/"). pydebug.h, main.c, pythonrun.c: define a private _Py_QnewFlag flag, true iff -Qnew is passed on the command line. This should go away (as the comments say) when true division becomes The Rule. This is deliberately not exposed to runtime inspection or modification: it's a one-way one-shot switch to pretend you're using Python 3. ceval.c: when _Py_QnewFlag is set, treat BINARY_DIVIDE as BINARY_TRUE_DIVIDE. test_{descr, generators, zipfile}.py: fiddle so these pass under -Qnew too. This was just a matter of s!/!//! in test_generators and test_zipfile. test_descr was trickier, as testbinop() is passed assumptions that "/" is the same as calling a "__div__" method; put a temporary hack there to call "__truediv__" instead when the method name is "__div__" and 1/2 evaluates to 0.5. Three standard tests still fail under -Qnew (on Windows; somebody please try the Linux tests with -Qnew too! Linux runs a whole bunch of tests Windows doesn't): test_augassign test_class test_coercion I can't stay awake longer to stare at this (be my guest). Offhand cures weren't obvious, nor was it even obvious that cures are possible without major hackery. Question: when -Qnew is in effect, should calls to __div__ magically change into calls to __truediv__? See "major hackery" at tail end of last paragraph <wink>.
Diffstat (limited to 'Python')
-rw-r--r--Python/ceval.c25
-rw-r--r--Python/pythonrun.c4
2 files changed, 18 insertions, 11 deletions
diff --git a/Python/ceval.c b/Python/ceval.c
index 5358517..76424e1 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -903,9 +903,22 @@ eval_frame(PyFrameObject *f)
break;
case BINARY_DIVIDE:
+ if (!_Py_QnewFlag) {
+ w = POP();
+ v = POP();
+ x = PyNumber_Divide(v, w);
+ Py_DECREF(v);
+ Py_DECREF(w);
+ PUSH(x);
+ if (x != NULL) continue;
+ break;
+ }
+ /* -Qnew is in effect: fall through to
+ BINARY_TRUE_DIVIDE */
+ case BINARY_TRUE_DIVIDE:
w = POP();
v = POP();
- x = PyNumber_Divide(v, w);
+ x = PyNumber_TrueDivide(v, w);
Py_DECREF(v);
Py_DECREF(w);
PUSH(x);
@@ -922,16 +935,6 @@ eval_frame(PyFrameObject *f)
if (x != NULL) continue;
break;
- case BINARY_TRUE_DIVIDE:
- w = POP();
- v = POP();
- x = PyNumber_TrueDivide(v, w);
- Py_DECREF(v);
- Py_DECREF(w);
- PUSH(x);
- if (x != NULL) continue;
- break;
-
case BINARY_MODULO:
w = POP();
v = POP();
diff --git a/Python/pythonrun.c b/Python/pythonrun.c
index 628058b..a8ad845 100644
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -64,6 +64,10 @@ int Py_UseClassExceptionsFlag = 1; /* Needed by bltinmodule.c: deprecated */
int Py_FrozenFlag; /* Needed by getpath.c */
int Py_UnicodeFlag = 0; /* Needed by compile.c */
int Py_IgnoreEnvironmentFlag; /* e.g. PYTHONPATH, PYTHONHOME */
+/* _XXX Py_QnewFlag should go away in 2.3. It's true iff -Qnew is passed,
+ on the command line, and is used in 2.2 by ceval.c to make all "/" divisions
+ true divisions (which they will be in 2.3). */
+int _Py_QnewFlag = 0;
static int initialized = 0;