Checkpoint. 218 tests are okay; 53 are failing. Done so far:

- all classes are new-style (but ripping out classobject.[ch] isn't done)
- int/int -> float
- all exceptions must derive from BaseException
- absolute import
- 'as' and 'with' are keywords
This commit is contained in:
Guido van Rossum 2006-03-15 04:58:47 +00:00
parent f3175f6341
commit 45aecf451a
24 changed files with 87 additions and 6365 deletions

View file

@ -3025,15 +3025,7 @@ do_raise(PyObject *type, PyObject *value, PyObject *tb)
Py_DECREF(tmp);
}
if (PyString_CheckExact(type)) {
/* Raising builtin string is deprecated but still allowed --
* do nothing. Raising an instance of a new-style str
* subclass is right out. */
if (PyErr_Warn(PyExc_DeprecationWarning,
"raising a string exception is deprecated"))
goto raise_error;
}
else if (PyExceptionClass_Check(type))
if (PyExceptionClass_Check(type))
PyErr_NormalizeException(&type, &value, &tb);
else if (PyExceptionInstance_Check(type)) {
@ -3054,10 +3046,8 @@ do_raise(PyObject *type, PyObject *value, PyObject *tb)
else {
/* Not something you can raise. You get an exception
anyway, just not what you specified :-) */
PyErr_Format(PyExc_TypeError,
"exceptions must be classes, instances, or "
"strings (deprecated), not %s",
type->ob_type->tp_name);
PyErr_SetString(PyExc_TypeError,
"exceptions must derive from BaseException");
goto raise_error;
}
PyErr_Restore(type, value, tb);
@ -4148,7 +4138,7 @@ build_class(PyObject *methods, PyObject *bases, PyObject *name)
if (g != NULL && PyDict_Check(g))
metaclass = PyDict_GetItemString(g, "__metaclass__");
if (metaclass == NULL)
metaclass = (PyObject *) &PyClass_Type;
metaclass = (PyObject *) &PyType_Type;
Py_INCREF(metaclass);
}
result = PyObject_CallFunction(metaclass, "OOO", name, bases, methods);

View file

@ -2464,11 +2464,7 @@ compiler_import(struct compiler *c, stmt_ty s)
int r;
PyObject *level;
if (c->c_flags && (c->c_flags->cf_flags & CO_FUTURE_ABSIMPORT))
level = PyInt_FromLong(0);
else
level = PyInt_FromLong(-1);
level = PyInt_FromLong(0);
if (level == NULL)
return 0;
@ -2511,12 +2507,7 @@ compiler_from_import(struct compiler *c, stmt_ty s)
if (!names)
return 0;
if (s->v.ImportFrom.level == 0 && c->c_flags &&
!(c->c_flags->cf_flags & CO_FUTURE_ABSIMPORT))
level = PyInt_FromLong(-1);
else
level = PyInt_FromLong(s->v.ImportFrom.level);
level = PyInt_FromLong(s->v.ImportFrom.level);
if (!level) {
Py_DECREF(names);
return 0;
@ -2746,10 +2737,7 @@ binop(struct compiler *c, operator_ty op)
case Mult:
return BINARY_MULTIPLY;
case Div:
if (c->c_flags && c->c_flags->cf_flags & CO_FUTURE_DIVISION)
return BINARY_TRUE_DIVIDE;
else
return BINARY_DIVIDE;
return BINARY_TRUE_DIVIDE;
case Mod:
return BINARY_MODULO;
case Pow:
@ -2809,10 +2797,7 @@ inplace_binop(struct compiler *c, operator_ty op)
case Mult:
return INPLACE_MULTIPLY;
case Div:
if (c->c_flags && c->c_flags->cf_flags & CO_FUTURE_DIVISION)
return INPLACE_TRUE_DIVIDE;
else
return INPLACE_DIVIDE;
return INPLACE_TRUE_DIVIDE;
case Mod:
return INPLACE_MODULO;
case Pow:

View file

@ -557,7 +557,8 @@ PyErr_NewException(char *name, PyObject *base, PyObject *dict)
bases = PyTuple_Pack(1, base);
if (bases == NULL)
goto failure;
result = PyClass_New(bases, dict, classname);
result = PyObject_CallFunction((PyObject *) (base->ob_type),
"OOO", classname, bases, dict);
failure:
Py_XDECREF(bases);
Py_XDECREF(mydict);

View file

@ -28,11 +28,11 @@ future_check_features(PyFutureFeatures *ff, stmt_ty s, const char *filename)
} else if (strcmp(feature, FUTURE_GENERATORS) == 0) {
continue;
} else if (strcmp(feature, FUTURE_DIVISION) == 0) {
ff->ff_features |= CO_FUTURE_DIVISION;
continue;
} else if (strcmp(feature, FUTURE_ABSIMPORT) == 0) {
ff->ff_features |= CO_FUTURE_ABSIMPORT;
continue;
} else if (strcmp(feature, FUTURE_WITH_STATEMENT) == 0) {
ff->ff_features |= CO_FUTURE_WITH_STATEMENT;
continue;
} else if (strcmp(feature, "braces") == 0) {
PyErr_SetString(PyExc_SyntaxError,
"not a chance");

View file

@ -486,15 +486,16 @@ converterr(const char *expected, PyObject *arg, char *msgbuf, size_t bufsize)
#define CONV_UNICODE "(unicode conversion error)"
/* explicitly check for float arguments when integers are expected. For now
* signal a warning. Returns true if an exception was raised. */
/* Explicitly check for float arguments when integers are expected.
Return 1 for error, 0 if ok. */
static int
float_argument_error(PyObject *arg)
{
if (PyFloat_Check(arg) &&
PyErr_Warn(PyExc_DeprecationWarning,
"integer argument expected, got float" ))
if (PyFloat_Check(arg)) {
PyErr_SetString(PyExc_TypeError,
"integer argument expected, got float" );
return 1;
}
else
return 0;
}

View file

@ -556,9 +556,8 @@ static state states_26[9] = {
static arc arcs_27_0[1] = {
{19, 1},
};
static arc arcs_27_1[3] = {
static arc arcs_27_1[2] = {
{78, 2},
{19, 2},
{0, 1},
};
static arc arcs_27_2[1] = {
@ -569,16 +568,15 @@ static arc arcs_27_3[1] = {
};
static state states_27[4] = {
{1, arcs_27_0},
{3, arcs_27_1},
{2, arcs_27_1},
{1, arcs_27_2},
{1, arcs_27_3},
};
static arc arcs_28_0[1] = {
{12, 1},
};
static arc arcs_28_1[3] = {
static arc arcs_28_1[2] = {
{78, 2},
{19, 2},
{0, 1},
};
static arc arcs_28_2[1] = {
@ -589,7 +587,7 @@ static arc arcs_28_3[1] = {
};
static state states_28[4] = {
{1, arcs_28_0},
{3, arcs_28_1},
{2, arcs_28_1},
{1, arcs_28_2},
{1, arcs_28_3},
};
@ -917,9 +915,8 @@ static state states_40[6] = {
{1, arcs_40_4},
{1, arcs_40_5},
};
static arc arcs_41_0[2] = {
static arc arcs_41_0[1] = {
{78, 1},
{19, 1},
};
static arc arcs_41_1[1] = {
{82, 2},
@ -928,7 +925,7 @@ static arc arcs_41_2[1] = {
{0, 2},
};
static state states_41[3] = {
{2, arcs_41_0},
{1, arcs_41_0},
{1, arcs_41_1},
{1, arcs_41_2},
};
@ -1870,7 +1867,7 @@ static dfa dfas[84] = {
{296, "with_stmt", 0, 6, states_40,
"\000\000\000\000\000\000\000\000\000\000\000\000\010\000\000\000\000\000\000\000\000"},
{297, "with_var", 0, 3, states_41,
"\000\000\010\000\000\000\000\000\000\100\000\000\000\000\000\000\000\000\000\000\000"},
"\000\000\000\000\000\000\000\000\000\100\000\000\000\000\000\000\000\000\000\000\000"},
{298, "except_clause", 0, 5, states_42,
"\000\000\000\000\000\000\000\000\000\000\000\000\040\000\000\000\000\000\000\000\000"},
{299, "suite", 0, 5, states_43,

View file

@ -28,7 +28,7 @@ extern time_t PyOS_GetLastModificationTime(char *, FILE *);
a .pyc file in text mode the magic number will be wrong; also, the
Apple MPW compiler swaps their values, botching string constants.
The magic numbers must be spaced apart atleast 2 values, as the
The magic numbers must be spaced apart at least 2 values, as the
-U interpeter flag will cause MAGIC+1 being used. They have been
odd numbers for some time now.
@ -56,9 +56,10 @@ extern time_t PyOS_GetLastModificationTime(char *, FILE *);
Python 2.5a0: 62081 (ast-branch)
Python 2.5a0: 62091 (with)
Python 2.5a0: 62092 (changed WITH_CLEANUP opcode)
Python 3000: 3000
.
*/
#define MAGIC (62092 | ((long)'\r'<<16) | ((long)'\n'<<24))
#define MAGIC (3000 | ((long)'\r'<<16) | ((long)'\n'<<24))
/* Magic word as global; note that _PyImport_Init() can change the
value of this global to accommodate for alterations of how the

View file

@ -696,9 +696,7 @@ PyRun_InteractiveLoopFlags(FILE *fp, const char *filename, PyCompilerFlags *flag
/* compute parser flags based on compiler flags */
#define PARSER_FLAGS(flags) \
((flags) ? ((((flags)->cf_flags & PyCF_DONT_IMPLY_DEDENT) ? \
PyPARSE_DONT_IMPLY_DEDENT : 0) \
| ((flags)->cf_flags & CO_FUTURE_WITH_STATEMENT ? \
PyPARSE_WITH_IS_KEYWORD : 0)) : 0)
PyPARSE_DONT_IMPLY_DEDENT : 0)) : 0)
int
PyRun_InteractiveOneFlags(FILE *fp, const char *filename, PyCompilerFlags *flags)