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

@ -7,18 +7,6 @@
# with someone who can; ask around on python-dev for help. Fred
# Drake <fdrake@acm.org> will probably be listening there.
# Commands for Kees Blom's railroad program
#diagram:token NAME
#diagram:token NUMBER
#diagram:token STRING
#diagram:token NEWLINE
#diagram:token ENDMARKER
#diagram:token INDENT
#diagram:output\input python.bla
#diagram:token DEDENT
#diagram:output\textwidth 20.04cm\oddsidemargin 0.0cm\evensidemargin 0.0cm
#diagram:rules
# Start symbols for the grammar:
# single_input is a single interactive statement;
# file_input is a module or sequence of commands read from an input file;
@ -61,8 +49,8 @@ import_stmt: import_name | import_from
import_name: 'import' dotted_as_names
import_from: ('from' ('.'* dotted_name | '.')
'import' ('*' | '(' import_as_names ')' | import_as_names))
import_as_name: NAME [('as' | NAME) NAME]
dotted_as_name: dotted_name [('as' | NAME) NAME]
import_as_name: NAME ['as' NAME]
dotted_as_name: dotted_name ['as' NAME]
import_as_names: import_as_name (',' import_as_name)* [',']
dotted_as_names: dotted_as_name (',' dotted_as_name)*
dotted_name: NAME ('.' NAME)*
@ -80,7 +68,7 @@ try_stmt: ('try' ':' suite
['finally' ':' suite] |
'finally' ':' suite))
with_stmt: 'with' test [ with_var ] ':' suite
with_var: ('as' | NAME) expr
with_var: 'as' expr
# NB compile.c makes sure that the default except clause is last
except_clause: 'except' [test [',' test]]
suite: simple_stmt | NEWLINE INDENT stmt+ DEDENT

View File

@ -41,17 +41,17 @@ typedef struct {
#define CO_NOFREE 0x0040
#if 0
/* This is no longer used. Stopped defining in 2.5, do not re-use. */
/* These are no longer used. */
#define CO_GENERATOR_ALLOWED 0x1000
#endif
#define CO_FUTURE_DIVISION 0x2000
#define CO_FUTURE_ABSIMPORT 0x4000 /* absolute import by default */
#define CO_FUTURE_WITH_STATEMENT 0x8000
#endif
/* This should be defined if a future statement modifies the syntax.
For example, when a keyword is added.
*/
#define PY_PARSER_REQUIRES_FUTURE_KEYWORD
/* #define PY_PARSER_REQUIRES_FUTURE_KEYWORD */
#define CO_MAXBLOCKS 20 /* Max static block nesting within a function */

View File

@ -23,7 +23,9 @@ typedef struct {
#define PyPARSE_DONT_IMPLY_DEDENT 0x0002
#if 0
#define PyPARSE_WITH_IS_KEYWORD 0x0003
#endif
PyAPI_FUNC(node *) PyParser_ParseString(const char *, grammar *, int,
perrdetail *);

View File

@ -1,9 +1,5 @@
/* Newfangled version identification scheme.
This scheme was added in Python 1.5.2b2; before that time, only PATCHLEVEL
was available. To test for presence of the scheme, test for
defined(PY_MAJOR_VERSION).
/* Python version identification scheme.
When the major or minor version changes, the VERSION variable in
configure.in must also be changed.
@ -19,14 +15,14 @@
/* Higher for patch releases */
/* Version parsed out into numeric values */
#define PY_MAJOR_VERSION 2
#define PY_MINOR_VERSION 5
#define PY_MAJOR_VERSION 0
#define PY_MINOR_VERSION 0
#define PY_MICRO_VERSION 0
#define PY_RELEASE_LEVEL PY_RELEASE_LEVEL_ALPHA
#define PY_RELEASE_SERIAL 0
/* Version as a string */
#define PY_VERSION "2.5a0"
#define PY_VERSION "3.0x"
/* Subversion Revision number of this file (not of the repository) */
#define PY_PATCHLEVEL_REVISION "$Revision$"

View File

@ -29,24 +29,17 @@ PyAPI_FUNC(void) PyErr_NormalizeException(PyObject**, PyObject**, PyObject**);
/* */
#define PyExceptionClass_Check(x) \
(PyClass_Check((x)) \
|| (PyType_Check((x)) && PyType_IsSubtype( \
(PyTypeObject*)(x), (PyTypeObject*)PyExc_BaseException)))
(PyType_Check((x)) && PyType_IsSubtype( \
(PyTypeObject*)(x), (PyTypeObject*)PyExc_BaseException))
#define PyExceptionInstance_Check(x) \
(PyInstance_Check((x)) || \
(PyType_IsSubtype((x)->ob_type, (PyTypeObject*)PyExc_BaseException)))
(PyType_IsSubtype((x)->ob_type, (PyTypeObject*)PyExc_BaseException))
#define PyExceptionClass_Name(x) \
(PyClass_Check((x)) \
? PyString_AS_STRING(((PyClassObject*)(x))->cl_name) \
: (char *)(((PyTypeObject*)(x))->tp_name))
((char *)(((PyTypeObject*)(x))->tp_name))
#define PyExceptionInstance_Class(x) \
((PyInstance_Check((x)) \
? (PyObject*)((PyInstanceObject*)(x))->in_class \
: (PyObject*)((x)->ob_type)))
#define PyExceptionInstance_Class(x) ((PyObject*)((x)->ob_type))
/* Predefined exceptions */

View File

@ -7,9 +7,8 @@
extern "C" {
#endif
#define PyCF_MASK (CO_FUTURE_DIVISION | CO_FUTURE_ABSIMPORT | \
CO_FUTURE_WITH_STATEMENT)
#define PyCF_MASK_OBSOLETE (CO_NESTED)
#define PyCF_MASK 0
#define PyCF_MASK_OBSOLETE 0
#define PyCF_SOURCE_IS_UTF8 0x0100
#define PyCF_DONT_IMPLY_DEDENT 0x0200
#define PyCF_ONLY_AST 0x0400

View File

@ -4,17 +4,12 @@ This is only useful to add pickle support for extension types defined in
C, not for instances of user-defined classes.
"""
from types import ClassType as _ClassType
__all__ = ["pickle", "constructor",
"add_extension", "remove_extension", "clear_extension_cache"]
dispatch_table = {}
def pickle(ob_type, pickle_function, constructor_ob=None):
if type(ob_type) is _ClassType:
raise TypeError("copy_reg is not intended for use with classes")
if not callable(pickle_function):
raise TypeError("reduction functions must be callable")
dispatch_table[ob_type] = pickle_function

View File

@ -16,7 +16,7 @@ import re
import string
import sys
from errors import DistutilsPlatformError
from .errors import DistutilsPlatformError
# These are needed in a couple of spots, so just compute them once.
PREFIX = os.path.normpath(sys.prefix)

View File

@ -27,7 +27,8 @@ Written by Marc-Andre Lemburg (mal@lemburg.com).
"""#"
import codecs, types, aliases
import codecs, types
from . import aliases
_cache = {}
_unknown = '--unknown--'

View File

@ -25,9 +25,9 @@ if n != 90:
print '2.2 raise class exceptions'
class AClass: pass
class AClass(Exception): pass
class BClass(AClass): pass
class CClass: pass
class CClass(Exception): pass
class DClass(AClass):
def __init__(self, ignore):
pass
@ -58,8 +58,8 @@ except AClass, v:
if v != b: raise TestFailed, "v!=b AClass"
# not enough arguments
try: raise BClass, a
except TypeError: pass
##try: raise BClass, a
##except TypeError: pass
try: raise DClass, a
except DClass, v:

6223
Misc/NEWS

File diff suppressed because it is too large Load Diff

View File

@ -2,7 +2,6 @@
#include "Python.h"
#include "osdefs.h"
#include "code.h" /* For CO_FUTURE_DIVISION */
#include "import.h"
#ifdef __VMS
@ -34,7 +33,7 @@ static char **orig_argv;
static int orig_argc;
/* command line options */
#define BASE_OPTS "c:dEhim:OQ:StuUvVW:xX"
#define BASE_OPTS "c:dEhim:OStuvVW:xX"
#ifndef RISCOS
#define PROGRAM_OPTS BASE_OPTS
@ -64,7 +63,6 @@ static char *usage_2 = "\
-m mod : run library module as a script (terminates option list)\n\
-O : optimize generated bytecode (a tad; also PYTHONOPTIMIZE=x)\n\
-OO : remove doc-strings in addition to the -O optimizations\n\
-Q arg : division options: -Qold (default), -Qwarn, -Qwarnall, -Qnew\n\
-S : don't imply 'import site' on initialization\n\
-t : issue warnings about inconsistent tab usage (-tt: issue errors)\n\
-u : unbuffered binary stdout and stderr (also PYTHONUNBUFFERED=x)\n\
@ -220,33 +218,6 @@ Py_Main(int argc, char **argv)
Py_DebugFlag++;
break;
case 'Q':
if (strcmp(_PyOS_optarg, "old") == 0) {
Py_DivisionWarningFlag = 0;
break;
}
if (strcmp(_PyOS_optarg, "warn") == 0) {
Py_DivisionWarningFlag = 1;
break;
}
if (strcmp(_PyOS_optarg, "warnall") == 0) {
Py_DivisionWarningFlag = 2;
break;
}
if (strcmp(_PyOS_optarg, "new") == 0) {
/* This only affects __main__ */
cf.cf_flags |= CO_FUTURE_DIVISION;
/* And this tells the eval loop to treat
BINARY_DIVIDE as BINARY_TRUE_DIVIDE */
_Py_QnewFlag = 1;
break;
}
fprintf(stderr,
"-Q option should be `-Qold', "
"`-Qwarn', `-Qwarnall', or `-Qnew' only\n");
return usage(2, argv[0]);
/* NOTREACHED */
case 'i':
inspect++;
saw_inspect_flag = 1;
@ -288,12 +259,10 @@ Py_Main(int argc, char **argv)
skipfirstline = 1;
break;
case 'U':
Py_UnicodeFlag++;
break;
case 'h':
help++;
break;
case 'V':
version++;
break;

View File

@ -2106,12 +2106,7 @@ recursive_isinstance(PyObject *inst, PyObject *cls, int recursion_depth)
return -1;
}
if (PyClass_Check(cls) && PyInstance_Check(inst)) {
PyObject *inclass =
(PyObject*)((PyInstanceObject*)inst)->in_class;
retval = PyClass_IsSubclass(inclass, cls);
}
else if (PyType_Check(cls)) {
if (PyType_Check(cls)) {
retval = PyObject_TypeCheck(inst, (PyTypeObject *)cls);
if (retval == 0) {
PyObject *c = PyObject_GetAttr(inst, __class__);
@ -2177,7 +2172,7 @@ recursive_issubclass(PyObject *derived, PyObject *cls, int recursion_depth)
{
int retval;
if (!PyClass_Check(derived) || !PyClass_Check(cls)) {
{
if (!check_class(derived,
"issubclass() arg 1 must be a class"))
return -1;
@ -2212,11 +2207,6 @@ recursive_issubclass(PyObject *derived, PyObject *cls, int recursion_depth)
retval = abstract_issubclass(derived, cls);
}
else {
/* shortcut */
if (!(retval = (derived == cls)))
retval = PyClass_IsSubclass(derived, cls);
}
return retval;
}

View File

@ -149,6 +149,7 @@ classify(parser_state *ps, int type, char *str)
strcmp(l->lb_str, s) != 0)
continue;
#ifdef PY_PARSER_REQUIRES_FUTURE_KEYWORD
/* Leaving this in as an example */
if (!(ps->p_flags & CO_FUTURE_WITH_STATEMENT)) {
if (s[0] == 'w' && strcmp(s, "with") == 0)
break; /* not a keyword yet */
@ -177,6 +178,7 @@ classify(parser_state *ps, int type, char *str)
}
#ifdef PY_PARSER_REQUIRES_FUTURE_KEYWORD
/* Leaving this in as an example */
static void
future_hack(parser_state *ps)
{

View File

@ -192,7 +192,8 @@ parsetok(struct tok_state *tok, grammar *g, int start, perrdetail *err_ret,
col_offset = -1;
if ((err_ret->error =
PyParser_AddToken(ps, (int)type, str, tok->lineno, col_offset,
PyParser_AddToken(ps, (int)type, str,
tok->lineno, col_offset,
&(err_ret->expected))) != E_OK) {
if (err_ret->error != E_DONE)
PyObject_FREE(str);

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);
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);
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;
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;
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

@ -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)

4
README
View File

@ -1,5 +1,5 @@
This is Python version 2.5 alpha 0
==================================
This is Python 3000 -- unversioned (branched off 2.5 pre alpha 1)
=================================================================
Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006 Python Software Foundation.
All rights reserved.