Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d32ed6f

Browse files
committed
Merged revisions 59933-59951 via svnmerge from
svn+ssh://[email protected]/python/trunk ........ r59935 | raymond.hettinger | 2008-01-13 07:15:15 +0100 (Sun, 13 Jan 2008) | 1 line Named tuple is a concept, not a specific type. ........ r59936 | raymond.hettinger | 2008-01-13 07:18:07 +0100 (Sun, 13 Jan 2008) | 1 line Fix spelling. ........ r59937 | georg.brandl | 2008-01-13 10:36:18 +0100 (Sun, 13 Jan 2008) | 2 lines Clarify the effect of text mode. ........ r59938 | thomas.heller | 2008-01-13 12:19:43 +0100 (Sun, 13 Jan 2008) | 1 line Make Modules/socketobject.c compile for Windows again. ........ r59939 | ka-ping.yee | 2008-01-13 12:25:13 +0100 (Sun, 13 Jan 2008) | 9 lines Check in the patch proposed by Ben Hayden (benjhayden) for issue #1550: help('modules') broken by several 3rd party libraries. Tested with Python build: trunk:54235:59936M -- the reported error occurs with Django installed (or with any __init__.py present on the path that raises an exception), and such errors indeed go away when this change is applied. ........ r59940 | georg.brandl | 2008-01-13 16:04:05 +0100 (Sun, 13 Jan 2008) | 2 lines Back out r59931 - test_ctypes fails with it. ........ r59943 | amaury.forgeotdarc | 2008-01-14 01:22:44 +0100 (Mon, 14 Jan 2008) | 6 lines As discussed in issue 1700288: ctypes takes some liberties when creating python types: it modifies the types' __dict__ directly, bypassing all the machinery of type objects which deal with special methods. And this broke recent optimisations of method lookup. Now we try to modify the type with more "official" functions. ........ r59944 | amaury.forgeotdarc | 2008-01-14 01:29:41 +0100 (Mon, 14 Jan 2008) | 5 lines Re-apply patch #1700288 (first applied in r59931, rolled back in r59940) now that ctypes uses a more supported method to create types: Method cache optimization, by Armin Rigo, ported to 2.6 by Kevin Jacobs. ........ r59946 | amaury.forgeotdarc | 2008-01-14 02:07:27 +0100 (Mon, 14 Jan 2008) | 4 lines ?Why did my tests not notice this before? Slots inheritance is very different from OO inheritance. This code lead to infinite recursion on classes derived from StructType. ........ r59947 | christian.heimes | 2008-01-14 04:33:52 +0100 (Mon, 14 Jan 2008) | 1 line Added new an better structseq representation. E.g. repr(time.gmtime(0)) now returns 'time.struct_time(tm_year=1970, tm_mon=1, tm_mday=1, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=3, tm_yday=1, tm_isdst=0)' instead of '(1970, 1, 1, 0, 0, 0, 3, 1, 0)'. The feature is part of #1816: sys.flags ........ r59948 | christian.heimes | 2008-01-14 04:35:38 +0100 (Mon, 14 Jan 2008) | 1 line I missed the most important file ........ r59949 | christian.heimes | 2008-01-14 04:42:48 +0100 (Mon, 14 Jan 2008) | 1 line Applied patch #1816: sys.flags patch ........ r59950 | christian.heimes | 2008-01-14 05:13:37 +0100 (Mon, 14 Jan 2008) | 2 lines Now that I've learnt about structseq objects I felt like converting sys.float_info to a structseq. It's readonly and help(sys.float_info) explains the attributes nicely. ........ r59951 | christian.heimes | 2008-01-14 07:06:19 +0100 (Mon, 14 Jan 2008) | 1 line Added more comments to the new structseq repr code and implemented several of Neal's suggestions. ........
1 parent 1acde19 commit d32ed6f

13 files changed

Lines changed: 336 additions & 60 deletions

File tree

Doc/c-api/concrete.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ Floating Point Objects
433433

434434
.. cfunction:: PyObject* PyFloat_GetInfo(void)
435435

436-
Return a :ctype:`PyDictObject` object which contains information about the
436+
Return a structseq instance which contains information about the
437437
precision, minimum and maximum values of a float. It's a thin wrapper
438438
around the header file :file:`float.h`.
439439

Doc/glossary.rst

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -329,11 +329,17 @@ Glossary
329329
also :term:`immutable`.
330330

331331
named tuple
332-
A tuple subclass whose elements also are accessible as attributes via
333-
fixed names (the class name and field names are indicated in the
334-
individual documentation of a named tuple type, like ``TestResults(failed,
335-
attempted)``). Named tuple classes are created by
336-
:func:`collections.namedtuple`.
332+
Any tuple-like class whose indexable fields are also accessible with
333+
named attributes (for example, :func:`time.localtime` returns a
334+
tuple-like object where the *year* is accessible either with an
335+
index such as ``t[0]`` or with a named attribute like ``t.tm_year``).
336+
337+
A named tuple can be a built-in type such as :class:`time.struct_time`,
338+
or it can be created with a regular class definition. A full featured
339+
named tuple can also be created with the factory function
340+
:func:`collections.namedtuple`. The latter approach automatically
341+
provides extra features such as a self-documenting representation like
342+
``Employee(name='jones', title='programmer')``.
337343

338344
namespace
339345
The place where a variable is stored. Namespaces are implemented as

Doc/library/functions.rst

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -743,10 +743,17 @@ available. They are listed here in alphabetical order.
743743
* 'U' universal newline mode (for backwards compatibility;
744744
unnecessary in new code)
745745

746-
Combine ``'b'`` with ``'r'``, ``'w'``, or ``'a'``, for binary
747-
mode, e.g., ``'rb'`` to open a file for reading in binary mode.
748-
Modes ``'r+'``, ``'w+'`` and ``'a+'`` open the file for updating (note
749-
that ``'w+'`` truncates the file).
746+
The most commonly-used values of *mode* are ``'r'`` for reading, ``'w'`` for
747+
writing (truncating the file if it already exists), and ``'a'`` for appending
748+
(which on *some* Unix systems means that *all* writes append to the end of the
749+
file regardless of the current seek position). If *mode* is omitted, it
750+
defaults to ``'r'``. The default is to use text mode, which may convert
751+
``'\n'`` characters to a platform-specific representation on writing and back
752+
on reading. Thus, when opening a binary file, you should append ``'b'`` to
753+
the *mode* value to open the file in binary mode, which will improve
754+
portability. (Appending ``'b'`` is useful even on systems that don't treat
755+
binary and text files differently, where it serves as documentation.) See below
756+
for more possible values of *mode*.
750757

751758
Python distinguishes between files opened in binary and text modes, even
752759
when the underlying operating system doesn't. Files opened in binary

Doc/library/sys.rst

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,14 +184,52 @@ always available.
184184
error occurs.
185185

186186

187+
.. data:: flags
188+
189+
The struct sequence *flags* exposes the status of command line flags. The
190+
attributes are read only.
191+
192+
+------------------------------+------------------------------------------+
193+
| attribute | flag |
194+
+==============================+==========================================+
195+
| :const:`debug` | -d |
196+
+------------------------------+------------------------------------------+
197+
| :const:`py3k_warning` | -3 |
198+
+------------------------------+------------------------------------------+
199+
| :const:`division_warning` | -Q |
200+
+------------------------------+------------------------------------------+
201+
| :const:`division_new` | -Qnew |
202+
+------------------------------+------------------------------------------+
203+
| :const:`inspect` | -i |
204+
+------------------------------+------------------------------------------+
205+
| :const:`interactive` | -i |
206+
+------------------------------+------------------------------------------+
207+
| :const:`optimize` | -O or -OO |
208+
+------------------------------+------------------------------------------+
209+
| :const:`dont_write_bytecode` | -B |
210+
+------------------------------+------------------------------------------+
211+
| :const:`no_site` | -S |
212+
+------------------------------+------------------------------------------+
213+
| :const:`ingnore_environment` | -E |
214+
+------------------------------+------------------------------------------+
215+
| :const:`tabcheck` | -t or -tt |
216+
+------------------------------+------------------------------------------+
217+
| :const:`verbose` | -v |
218+
+------------------------------+------------------------------------------+
219+
| :const:`unicode` | -U |
220+
+------------------------------+------------------------------------------+
221+
222+
.. versionadded:: 2.6
223+
224+
187225
.. data:: float_info
188226

189-
A dict holding information about the float type. It contains low level
227+
A structseq holding information about the float type. It contains low level
190228
information about the precision and internal representation. Please study
191229
your system's :file:`float.h` for more information.
192230

193231
+---------------------+--------------------------------------------------+
194-
| key | explanation |
232+
| attribute | explanation |
195233
+=====================+==================================================+
196234
| :const:`epsilon` | Difference between 1 and the next representable |
197235
| | floating point number |

Lib/pydoc.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1834,7 +1834,9 @@ def callback(path, modname, desc, modules=modules):
18341834
modname = modname[:-9] + ' (package)'
18351835
if modname.find('.') < 0:
18361836
modules[modname] = 1
1837-
ModuleScanner().run(callback)
1837+
def onerror(modname):
1838+
callback(None, modname, None)
1839+
ModuleScanner().run(callback, onerror=onerror)
18381840
self.list(modules.keys())
18391841
self.output.write('''
18401842
Enter any module name to get more help. Or, type "modules spam" to search
@@ -1870,7 +1872,7 @@ def next(self):
18701872
class ModuleScanner:
18711873
"""An interruptible scanner that searches module synopses."""
18721874

1873-
def run(self, callback, key=None, completer=None):
1875+
def run(self, callback, key=None, completer=None, onerror=None):
18741876
if key: key = key.lower()
18751877
self.quit = False
18761878
seen = {}
@@ -1887,7 +1889,7 @@ def run(self, callback, key=None, completer=None):
18871889
if name.lower().find(key) >= 0:
18881890
callback(None, modname, desc)
18891891

1890-
for importer, modname, ispkg in pkgutil.walk_packages():
1892+
for importer, modname, ispkg in pkgutil.walk_packages(onerror=onerror):
18911893
if self.quit:
18921894
break
18931895
if key is None:

Lib/test/test_structseq.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@ def test_tuple(self):
2828

2929
def test_repr(self):
3030
t = time.gmtime()
31-
repr(t)
31+
self.assert_(repr(t))
32+
t = time.gmtime(0)
33+
self.assertEqual(repr(t),
34+
"time.struct_time(tm_year=1970, tm_mon=1, tm_mday=1, tm_hour=0, "
35+
"tm_min=0, tm_sec=0, tm_wday=3, tm_yday=1, tm_isdst=0)")
3236

3337
def test_concat(self):
3438
t1 = time.gmtime()

Lib/test/test_sys.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,8 @@ def test_attributes(self):
279279
self.assert_(isinstance(sys.copyright, str))
280280
self.assert_(isinstance(sys.exec_prefix, str))
281281
self.assert_(isinstance(sys.executable, str))
282-
self.assert_(isinstance(sys.float_info, dict))
283282
self.assertEqual(len(sys.float_info), 11)
283+
self.assertEqual(sys.float_info.radix, 2)
284284
self.assert_(isinstance(sys.hexversion, int))
285285
self.assert_(isinstance(sys.maxsize, int))
286286
self.assert_(isinstance(sys.maxunicode, int))
@@ -320,6 +320,17 @@ def __hash__(self):
320320
self.assertRaises(TypeError, sys.intern, S("abc"))
321321

322322

323+
def test_sys_flags(self):
324+
self.failUnless(sys.flags)
325+
attrs = ("debug", "division_warning",
326+
"inspect", "interactive", "optimize", "dont_write_bytecode",
327+
"no_site", "ingnore_environment", "tabcheck", "verbose")
328+
for attr in attrs:
329+
self.assert_(hasattr(sys.flags, attr), attr)
330+
self.assertEqual(type(getattr(sys.flags, attr)), int, attr)
331+
self.assert_(repr(sys.flags))
332+
333+
323334
def test_main():
324335
test.test_support.run_unittest(SysModuleTest)
325336

Modules/_ctypes/_ctypes.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ static int
401401
StructType_setattro(PyObject *self, PyObject *key, PyObject *value)
402402
{
403403
/* XXX Should we disallow deleting _fields_? */
404-
if (-1 == PyObject_GenericSetAttr(self, key, value))
404+
if (-1 == PyType_Type.tp_setattro(self, key, value))
405405
return -1;
406406

407407
if (value && PyUnicode_Check(key) &&

Modules/_ctypes/stgdict.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ StructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct)
458458
Py_DECREF(pair);
459459
return -1;
460460
}
461-
if (-1 == PyDict_SetItem(realdict, name, prop)) {
461+
if (-1 == PyObject_SetAttr(type, name, prop)) {
462462
Py_DECREF(prop);
463463
Py_DECREF(pair);
464464
return -1;

Modules/socketmodule.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4979,10 +4979,13 @@ init_socket(void)
49794979
#endif
49804980

49814981
#ifdef SIO_RCVALL
4982-
tmp = PyLong_FromUnsignedLong(SIO_RCVALL);
4983-
if (tmp == NULL)
4984-
return;
4985-
PyModule_AddObject(m, "SIO_RCVALL", tmp);
4982+
{
4983+
PyObject *tmp;
4984+
tmp = PyLong_FromUnsignedLong(SIO_RCVALL);
4985+
if (tmp == NULL)
4986+
return;
4987+
PyModule_AddObject(m, "SIO_RCVALL", tmp);
4988+
}
49864989
PyModule_AddIntConstant(m, "RCVALL_OFF", RCVALL_OFF);
49874990
PyModule_AddIntConstant(m, "RCVALL_ON", RCVALL_ON);
49884991
PyModule_AddIntConstant(m, "RCVALL_SOCKETLEVELONLY", RCVALL_SOCKETLEVELONLY);

0 commit comments

Comments
 (0)