mirror of
https://github.com/python/cpython.git
synced 2025-11-25 04:34:37 +00:00
Kill off softspace completely (except in formatter.py which seems to have
a different feature with the same name). The change to test_doctest.txt reduces the doctest failures to 3.
This commit is contained in:
parent
bdc36e4d9e
commit
79139b247b
19 changed files with 10 additions and 163 deletions
|
|
@ -40,8 +40,6 @@ PyAPI_FUNC(int) PyEval_GetRestricted(void);
|
|||
flag was set, else return 0. */
|
||||
PyAPI_FUNC(int) PyEval_MergeCompilerFlags(PyCompilerFlags *cf);
|
||||
|
||||
PyAPI_FUNC(int) Py_FlushLine(void);
|
||||
|
||||
PyAPI_FUNC(int) Py_AddPendingCall(int (*func)(void *), void *arg);
|
||||
PyAPI_FUNC(int) Py_MakePendingCalls(void);
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@ typedef struct {
|
|||
PyObject *f_name;
|
||||
PyObject *f_mode;
|
||||
int (*f_close)(FILE *);
|
||||
int f_softspace; /* Flag used by 'print' command */
|
||||
int f_binary; /* Flag which indicates whether the file is
|
||||
open in binary (1) or text (0) mode */
|
||||
char* f_buf; /* Allocated readahead buffer */
|
||||
|
|
@ -41,7 +40,6 @@ PyAPI_FUNC(FILE *) PyFile_AsFile(PyObject *);
|
|||
PyAPI_FUNC(PyObject *) PyFile_Name(PyObject *);
|
||||
PyAPI_FUNC(PyObject *) PyFile_GetLine(PyObject *, int);
|
||||
PyAPI_FUNC(int) PyFile_WriteObject(PyObject *, PyObject *, int);
|
||||
PyAPI_FUNC(int) PyFile_SoftSpace(PyObject *, int);
|
||||
PyAPI_FUNC(int) PyFile_WriteString(const char *, PyObject *);
|
||||
PyAPI_FUNC(int) PyObject_AsFileDescriptor(PyObject *);
|
||||
|
||||
|
|
|
|||
|
|
@ -60,7 +60,6 @@ class StringIO:
|
|||
self.buflist = []
|
||||
self.pos = 0
|
||||
self.closed = False
|
||||
self.softspace = 0
|
||||
|
||||
def __iter__(self):
|
||||
return self
|
||||
|
|
|
|||
|
|
@ -39,7 +39,6 @@ class DBRecIO:
|
|||
self.len = None
|
||||
self.pos = 0
|
||||
self.closed = 0
|
||||
self.softspace = 0
|
||||
|
||||
def close(self):
|
||||
if not self.closed:
|
||||
|
|
|
|||
16
Lib/code.py
16
Lib/code.py
|
|
@ -12,19 +12,6 @@ from codeop import CommandCompiler, compile_command
|
|||
__all__ = ["InteractiveInterpreter", "InteractiveConsole", "interact",
|
||||
"compile_command"]
|
||||
|
||||
def softspace(file, newvalue):
|
||||
oldvalue = 0
|
||||
try:
|
||||
oldvalue = file.softspace
|
||||
except AttributeError:
|
||||
pass
|
||||
try:
|
||||
file.softspace = newvalue
|
||||
except (AttributeError, TypeError):
|
||||
# "attribute-less object" or "read-only attributes"
|
||||
pass
|
||||
return oldvalue
|
||||
|
||||
class InteractiveInterpreter:
|
||||
"""Base class for InteractiveConsole.
|
||||
|
||||
|
|
@ -105,9 +92,6 @@ class InteractiveInterpreter:
|
|||
raise
|
||||
except:
|
||||
self.showtraceback()
|
||||
else:
|
||||
if softspace(sys.stdout, 0):
|
||||
print()
|
||||
|
||||
def showsyntaxerror(self, filename=None):
|
||||
"""Display the syntax error that just occurred.
|
||||
|
|
|
|||
|
|
@ -240,16 +240,10 @@ class _SpoofOut(StringIO):
|
|||
# that a trailing newline is missing.
|
||||
if result and not result.endswith("\n"):
|
||||
result += "\n"
|
||||
# Prevent softspace from screwing up the next test case, in
|
||||
# case they used print with a trailing comma in an example.
|
||||
if hasattr(self, "softspace"):
|
||||
del self.softspace
|
||||
return result
|
||||
|
||||
def truncate(self, size=None):
|
||||
StringIO.truncate(self, size)
|
||||
if hasattr(self, "softspace"):
|
||||
del self.softspace
|
||||
|
||||
# Worst-case linear-time ellipsis matching.
|
||||
def _ellipsis_match(want, got):
|
||||
|
|
|
|||
|
|
@ -1223,7 +1223,6 @@ class PyShell(OutputWindow):
|
|||
self.text.insert("end-1c", "\n")
|
||||
self.text.mark_set("iomark", "end-1c")
|
||||
self.set_line_and_column()
|
||||
sys.stdout.softspace = 0
|
||||
|
||||
def write(self, s, tags=()):
|
||||
try:
|
||||
|
|
@ -1242,7 +1241,6 @@ class PseudoFile(object):
|
|||
def __init__(self, shell, tags, encoding=None):
|
||||
self.shell = shell
|
||||
self.tags = tags
|
||||
self.softspace = 0
|
||||
self.encoding = encoding
|
||||
|
||||
def write(self, s):
|
||||
|
|
|
|||
|
|
@ -190,12 +190,7 @@ def cleanup_traceback(tb, exclude):
|
|||
tb[i] = fn, ln, nm, line
|
||||
|
||||
def flush_stdout():
|
||||
try:
|
||||
if sys.stdout.softspace:
|
||||
sys.stdout.softspace = 0
|
||||
sys.stdout.write("\n")
|
||||
except (AttributeError, EOFError):
|
||||
pass
|
||||
"""XXX How to do this now?"""
|
||||
|
||||
def exit():
|
||||
"""Exit subprocess, possibly after first deleting sys.exitfunc
|
||||
|
|
|
|||
|
|
@ -202,7 +202,7 @@ class _fileobject(object):
|
|||
default_bufsize = 8192
|
||||
name = "<socket>"
|
||||
|
||||
__slots__ = ["mode", "bufsize", "softspace",
|
||||
__slots__ = ["mode", "bufsize",
|
||||
# "closed" is a property, see below
|
||||
"_sock", "_rbufsize", "_wbufsize", "_rbuf", "_wbuf",
|
||||
"_close"]
|
||||
|
|
@ -213,7 +213,6 @@ class _fileobject(object):
|
|||
if bufsize < 0:
|
||||
bufsize = self.default_bufsize
|
||||
self.bufsize = bufsize
|
||||
self.softspace = False
|
||||
if bufsize == 0:
|
||||
self._rbufsize = 1
|
||||
elif bufsize == 1:
|
||||
|
|
|
|||
|
|
@ -9,9 +9,9 @@ already:
|
|||
We can make this fail by disabling the blank-line feature.
|
||||
|
||||
>>> if 1:
|
||||
... print 'a'
|
||||
... print
|
||||
... print 'b'
|
||||
... print('a')
|
||||
... print()
|
||||
... print('b')
|
||||
a
|
||||
<BLANKLINE>
|
||||
b
|
||||
|
|
|
|||
|
|
@ -30,14 +30,10 @@ class AutoFileTests(unittest.TestCase):
|
|||
def testAttributes(self):
|
||||
# verify expected attributes exist
|
||||
f = self.f
|
||||
softspace = f.softspace
|
||||
f.name # merely shouldn't blow up
|
||||
f.mode # ditto
|
||||
f.closed # ditto
|
||||
|
||||
# verify softspace is writable
|
||||
f.softspace = softspace # merely shouldn't blow up
|
||||
|
||||
# verify the others aren't
|
||||
for attr in 'name', 'mode', 'closed':
|
||||
self.assertRaises((AttributeError, TypeError), setattr, f, attr, 'oops')
|
||||
|
|
|
|||
|
|
@ -61,7 +61,6 @@ class TestPredicates(IsTestBase):
|
|||
self.istest(inspect.ismodule, 'mod')
|
||||
self.istest(inspect.istraceback, 'tb')
|
||||
self.istest(inspect.isdatadescriptor, '__builtin__.file.closed')
|
||||
self.istest(inspect.isdatadescriptor, '__builtin__.file.softspace')
|
||||
if hasattr(types, 'GetSetDescriptorType'):
|
||||
self.istest(inspect.isgetsetdescriptor,
|
||||
'type(tb.tb_frame).f_locals')
|
||||
|
|
|
|||
|
|
@ -1,14 +0,0 @@
|
|||
from test import test_support
|
||||
import StringIO
|
||||
|
||||
# SF bug 480215: softspace confused in nested print
|
||||
f = StringIO.StringIO()
|
||||
class C:
|
||||
def __str__(self):
|
||||
print('a', file=f)
|
||||
return 'b'
|
||||
|
||||
print(C(), 'c ', 'd\t', 'e', file=f)
|
||||
print('f', 'g', file=f)
|
||||
# In 2.2 & earlier, this printed ' a\nbc d\te\nf g\n'
|
||||
test_support.vereq(f.getvalue(), 'a\nb c d\te\nf g\n')
|
||||
|
|
@ -102,8 +102,6 @@ typedef struct {
|
|||
char* f_bufend; /* Points after last occupied position */
|
||||
char* f_bufptr; /* Current buffer position */
|
||||
|
||||
int f_softspace; /* Flag used by 'print' command */
|
||||
|
||||
int f_univ_newline; /* Handle any newline convention */
|
||||
int f_newlinetypes; /* Types of newlines seen */
|
||||
int f_skipnextlf; /* Skip next \n */
|
||||
|
|
@ -813,8 +811,6 @@ BZ2File_write(BZ2FileObject *self, PyObject *args)
|
|||
goto cleanup;
|
||||
}
|
||||
|
||||
self->f_softspace = 0;
|
||||
|
||||
Py_BEGIN_ALLOW_THREADS
|
||||
BZ2_bzWrite (&bzerror, self->fp, buf, len);
|
||||
self->pos += len;
|
||||
|
|
@ -934,8 +930,6 @@ BZ2File_writelines(BZ2FileObject *self, PyObject *seq)
|
|||
}
|
||||
}
|
||||
|
||||
self->f_softspace = 0;
|
||||
|
||||
/* Since we are releasing the global lock, the
|
||||
following code may *not* execute Python code. */
|
||||
Py_BEGIN_ALLOW_THREADS
|
||||
|
|
@ -1264,18 +1258,6 @@ static PyGetSetDef BZ2File_getset[] = {
|
|||
};
|
||||
|
||||
|
||||
/* ===================================================================== */
|
||||
/* Members of BZ2File_Type. */
|
||||
|
||||
#undef OFF
|
||||
#define OFF(x) offsetof(BZ2FileObject, x)
|
||||
|
||||
static PyMemberDef BZ2File_members[] = {
|
||||
{"softspace", T_INT, OFF(f_softspace), 0,
|
||||
"flag indicating that a space needs to be printed; used by print"},
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
/* ===================================================================== */
|
||||
/* Slot definitions for BZ2File_Type. */
|
||||
|
||||
|
|
@ -1501,7 +1483,7 @@ static PyTypeObject BZ2File_Type = {
|
|||
(getiterfunc)BZ2File_getiter, /*tp_iter*/
|
||||
(iternextfunc)BZ2File_iternext, /*tp_iternext*/
|
||||
BZ2File_methods, /*tp_methods*/
|
||||
BZ2File_members, /*tp_members*/
|
||||
0, /*tp_members*/
|
||||
BZ2File_getset, /*tp_getset*/
|
||||
0, /*tp_base*/
|
||||
0, /*tp_dict*/
|
||||
|
|
|
|||
|
|
@ -57,7 +57,6 @@ typedef struct { /* Subtype of IOobject */
|
|||
Py_ssize_t pos, string_size;
|
||||
|
||||
Py_ssize_t buf_size;
|
||||
int softspace;
|
||||
} Oobject;
|
||||
|
||||
/* Declarations for objects of type StringI */
|
||||
|
|
@ -489,13 +488,6 @@ static struct PyMethodDef O_methods[] = {
|
|||
{NULL, NULL} /* sentinel */
|
||||
};
|
||||
|
||||
static PyMemberDef O_memberlist[] = {
|
||||
{"softspace", T_INT, offsetof(Oobject, softspace), 0,
|
||||
"flag indicating that a space needs to be printed; used by print"},
|
||||
/* getattr(f, "closed") is implemented without this table */
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
static void
|
||||
O_dealloc(Oobject *self) {
|
||||
if (self->buf != NULL)
|
||||
|
|
@ -536,7 +528,7 @@ static PyTypeObject Otype = {
|
|||
PyObject_SelfIter, /*tp_iter */
|
||||
(iternextfunc)IO_iternext, /*tp_iternext */
|
||||
O_methods, /*tp_methods */
|
||||
O_memberlist, /*tp_members */
|
||||
0, /*tp_members */
|
||||
file_getsetlist, /*tp_getset */
|
||||
};
|
||||
|
||||
|
|
@ -549,7 +541,6 @@ newOobject(int size) {
|
|||
return NULL;
|
||||
self->pos=0;
|
||||
self->string_size = 0;
|
||||
self->softspace = 0;
|
||||
|
||||
self->buf = (char *)malloc(size);
|
||||
if (!self->buf) {
|
||||
|
|
|
|||
|
|
@ -118,7 +118,6 @@ fill_file_fields(PyFileObject *f, FILE *fp, PyObject *name, char *mode,
|
|||
f->f_mode = PyString_FromString(mode);
|
||||
|
||||
f->f_close = close;
|
||||
f->f_softspace = 0;
|
||||
f->f_binary = strchr(mode,'b') != NULL;
|
||||
f->f_buf = NULL;
|
||||
f->f_univ_newline = (strchr(mode, 'U') != NULL);
|
||||
|
|
@ -1523,7 +1522,6 @@ file_write(PyFileObject *f, PyObject *args)
|
|||
return err_closed();
|
||||
if (!PyArg_ParseTuple(args, f->f_binary ? "s#" : "t#", &s, &n))
|
||||
return NULL;
|
||||
f->f_softspace = 0;
|
||||
Py_BEGIN_ALLOW_THREADS
|
||||
errno = 0;
|
||||
n2 = fwrite(s, 1, n, f->f_fp);
|
||||
|
|
@ -1626,7 +1624,6 @@ file_writelines(PyFileObject *f, PyObject *seq)
|
|||
/* Since we are releasing the global lock, the
|
||||
following code may *not* execute Python code. */
|
||||
Py_BEGIN_ALLOW_THREADS
|
||||
f->f_softspace = 0;
|
||||
errno = 0;
|
||||
for (i = 0; i < j; i++) {
|
||||
line = PyList_GET_ITEM(list, i);
|
||||
|
|
@ -1786,8 +1783,6 @@ static PyMethodDef file_methods[] = {
|
|||
#define OFF(x) offsetof(PyFileObject, x)
|
||||
|
||||
static PyMemberDef file_memberlist[] = {
|
||||
{"softspace", T_INT, OFF(f_softspace), 0,
|
||||
"flag indicating that a space needs to be printed; used by print"},
|
||||
{"mode", T_OBJECT, OFF(f_mode), RO,
|
||||
"file mode ('r', 'U', 'w', 'a', possibly with 'b' or '+' added)"},
|
||||
{"name", T_OBJECT, OFF(f_name), RO,
|
||||
|
|
@ -2094,8 +2089,7 @@ PyTypeObject PyFile_Type = {
|
|||
0, /* tp_call */
|
||||
0, /* tp_str */
|
||||
PyObject_GenericGetAttr, /* tp_getattro */
|
||||
/* softspace is writable: we must supply tp_setattro */
|
||||
PyObject_GenericSetAttr, /* tp_setattro */
|
||||
0, /* tp_setattro */
|
||||
0, /* tp_as_buffer */
|
||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
|
||||
file_doc, /* tp_doc */
|
||||
|
|
@ -2119,42 +2113,6 @@ PyTypeObject PyFile_Type = {
|
|||
PyObject_Del, /* tp_free */
|
||||
};
|
||||
|
||||
/* Interface for the 'soft space' between print items. */
|
||||
|
||||
int
|
||||
PyFile_SoftSpace(PyObject *f, int newflag)
|
||||
{
|
||||
long oldflag = 0;
|
||||
if (f == NULL) {
|
||||
/* Do nothing */
|
||||
}
|
||||
else if (PyFile_Check(f)) {
|
||||
oldflag = ((PyFileObject *)f)->f_softspace;
|
||||
((PyFileObject *)f)->f_softspace = newflag;
|
||||
}
|
||||
else {
|
||||
PyObject *v;
|
||||
v = PyObject_GetAttrString(f, "softspace");
|
||||
if (v == NULL)
|
||||
PyErr_Clear();
|
||||
else {
|
||||
if (PyInt_CheckExact(v))
|
||||
oldflag = PyInt_AsLong(v);
|
||||
assert(oldflag < INT_MAX);
|
||||
Py_DECREF(v);
|
||||
}
|
||||
v = PyInt_FromLong((long)newflag);
|
||||
if (v == NULL)
|
||||
PyErr_Clear();
|
||||
else {
|
||||
if (PyObject_SetAttrString(f, "softspace", v) != 0)
|
||||
PyErr_Clear();
|
||||
Py_DECREF(v);
|
||||
}
|
||||
}
|
||||
return (int)oldflag;
|
||||
}
|
||||
|
||||
/* Interfaces to write objects/strings to file-like objects */
|
||||
|
||||
int
|
||||
|
|
|
|||
|
|
@ -3349,17 +3349,6 @@ PyEval_MergeCompilerFlags(PyCompilerFlags *cf)
|
|||
return result;
|
||||
}
|
||||
|
||||
int
|
||||
Py_FlushLine(void)
|
||||
{
|
||||
PyObject *f = PySys_GetObject("stdout");
|
||||
if (f == NULL)
|
||||
return 0;
|
||||
if (!PyFile_SoftSpace(f, 0))
|
||||
return 0;
|
||||
return PyFile_WriteString("\n", f);
|
||||
}
|
||||
|
||||
|
||||
/* External interface to call any callable object.
|
||||
The arg must be a tuple or NULL. */
|
||||
|
|
|
|||
|
|
@ -795,8 +795,6 @@ PyRun_InteractiveOneFlags(FILE *fp, const char *filename, PyCompilerFlags *flags
|
|||
return -1;
|
||||
}
|
||||
Py_DECREF(v);
|
||||
if (Py_FlushLine())
|
||||
PyErr_Clear();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -883,8 +881,6 @@ PyRun_SimpleFileExFlags(FILE *fp, const char *filename, int closeit,
|
|||
return -1;
|
||||
}
|
||||
Py_DECREF(v);
|
||||
if (Py_FlushLine())
|
||||
PyErr_Clear();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -902,8 +898,6 @@ PyRun_SimpleStringFlags(const char *command, PyCompilerFlags *flags)
|
|||
return -1;
|
||||
}
|
||||
Py_DECREF(v);
|
||||
if (Py_FlushLine())
|
||||
PyErr_Clear();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -1018,8 +1012,6 @@ handle_system_exit(void)
|
|||
int exitcode = 0;
|
||||
|
||||
PyErr_Fetch(&exception, &value, &tb);
|
||||
if (Py_FlushLine())
|
||||
PyErr_Clear();
|
||||
fflush(stdout);
|
||||
if (value == NULL || value == Py_None)
|
||||
goto done;
|
||||
|
|
@ -1097,8 +1089,6 @@ PyErr_PrintEx(int set_sys_last_vars)
|
|||
v2 = Py_None;
|
||||
Py_INCREF(v2);
|
||||
}
|
||||
if (Py_FlushLine())
|
||||
PyErr_Clear();
|
||||
fflush(stdout);
|
||||
PySys_WriteStderr("Error in sys.excepthook:\n");
|
||||
PyErr_Display(exception2, v2, tb2);
|
||||
|
|
@ -1128,8 +1118,6 @@ PyErr_Display(PyObject *exception, PyObject *value, PyObject *tb)
|
|||
if (f == NULL)
|
||||
fprintf(stderr, "lost sys.stderr\n");
|
||||
else {
|
||||
if (Py_FlushLine())
|
||||
PyErr_Clear();
|
||||
fflush(stdout);
|
||||
if (tb && tb != Py_None)
|
||||
err = PyTraceBack_Print(tb, f);
|
||||
|
|
@ -1597,8 +1585,6 @@ call_sys_exitfunc(void)
|
|||
Py_DECREF(exitfunc);
|
||||
}
|
||||
|
||||
if (Py_FlushLine())
|
||||
PyErr_Clear();
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -1855,4 +1841,3 @@ PyRun_InteractiveLoop(FILE *f, const char *p)
|
|||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -104,8 +104,6 @@ sys_displayhook(PyObject *self, PyObject *o)
|
|||
}
|
||||
if (PyObject_SetAttrString(builtins, "_", Py_None) != 0)
|
||||
return NULL;
|
||||
if (Py_FlushLine() != 0)
|
||||
return NULL;
|
||||
outf = PySys_GetObject("stdout");
|
||||
if (outf == NULL) {
|
||||
PyErr_SetString(PyExc_RuntimeError, "lost sys.stdout");
|
||||
|
|
@ -113,8 +111,7 @@ sys_displayhook(PyObject *self, PyObject *o)
|
|||
}
|
||||
if (PyFile_WriteObject(o, outf, 0) != 0)
|
||||
return NULL;
|
||||
PyFile_SoftSpace(outf, 1);
|
||||
if (Py_FlushLine() != 0)
|
||||
if (PyFile_WriteString("\n", outf) != 0)
|
||||
return NULL;
|
||||
if (PyObject_SetAttrString(builtins, "_", o) != 0)
|
||||
return NULL;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue