inicio mail me! sindicaci;ón

Updates from Python SVN, Part 19

Here we are with another update from Python 2.x SVN.

  • Added os.O_NOATIME constant. It serves the purpose to not update the access time within read operations.

  • Added os.fchmod() and os.fchown().

  • The new module has been deprecated. Use types instead.

  • sys.py3kwarning flag has been exposed. True when python is started with -3 flag on command line. Also warning.warnpy3k() has been added to help the transition.

  • Added PyFloat_GetMax, PyFloat_GetMin, PyFloat_GetInfo to the C API and float_info dictionary to the sys module which contains information about the internal floating point type.

  • Added test suite for the cmd module.

  • Added Python on Windows documentation.

  • Implemented PEP 366 (Main module explicit relative imports).

  • Support loading pickles of random.Random objects created on 32-bit systems on 64-bit systems, and vice versa. As a consequence of the change, Random pickles created by Python 2.6 cannot be loaded in Python 2.5.

  • Changed GeneratorExit’s base class from Exception to BaseException.

  • os.access now always returns True on Windows for any existing directory since there are no read only directories on Windows.

  • Added msvcrt.getwch(), msvcrt.getwche(), msvcrt.putwch(), msvcrt.ungetwch() to handle wide chars.

  • namedtuple.asdict and namedtuple.replace are now namedtuple._asdict() and namedtuple._replace()

  • Dictionary construction had a speed-up of about 10%. There is a new opcode, STORE_MAP that saves the compiler from awkward stack manipulations and specializes for dicts using PyDict_SetItem instead of PyObject_SetItem. From the log message:

Old disassembly:
              0 BUILD_MAP                0
              3 DUP_TOP             
              4 LOAD_CONST               1 (1)
              7 ROT_TWO             
              8 LOAD_CONST               2 ('x')
             11 STORE_SUBSCR        
             12 DUP_TOP             
             13 LOAD_CONST               3 (2)
             16 ROT_TWO             
             17 LOAD_CONST               4 ('y')
             20 STORE_SUBSCR 

New disassembly:
              0 BUILD_MAP                0
              3 LOAD_CONST               1 (1)    
              6 LOAD_CONST               2 ('x')
              9 STORE_MAP                
             10 LOAD_CONST               3 (2)  
             13 LOAD_CONST               4 ('y')
             16 STORE_MAP
  • Another optimization has been added: BUILD_MAP now has a meaning. It’s the estimated size of the dictionary. Allows dictionaries to be pre-sized (upto 255 elements) saving time lost to re-sizes with their attendant mallocs and re-insertions. Has zero effect on small dictionaries (5 elements or fewer), a slight benefit for dicts upto 22 elements (because they had to resize once anyway), and more benefit for dicts upto 255 elements (saving multiple resizes during the build-up and reducing the number of collisions on the first insertions). Beyond 255 elements, there is no addional benefit.

  • Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT. Macros for compatibility are available.

  • Added signal.set_wakeup_fd(). There is a correspondent C API as well: PySignal_SetWakeupFd.

  • Slightly change in __ hash __ behavior and rich comparison: __ hash __ can be inherited when one __ lt __, __ le __, __ gt __, __ ge __ are overridden, as long as __ eq __ and __ ne __ aren’t.

  • Improved performance of built-in any()/all() by avoiding PyIter_Next().

Updates from Python SVN, Part 18

IT’s been definitely a while since my last update but having a new job changes a lot my schedule.

  • In the httplib module there was a bug in reading data from the stream. HTTPConnection hanged when reading too much data at once. This has been fixed closing the connection after reading the whole stream.

  • In the decimal module the tuple constructor is now less permissive. It allowed bad coefficient numbers, floats in the sign and other stuff which generated the wrong number or let the algorithms misbehave.

  • mmap() has a new offset parameter to map a window of a file.

  • named_tuple has been renamed to namedtuple.

  • The sum() builtin function has been optimized for integer and floats: it keeps temporary sums in C instead of new Python objects assuming operands are all of the same type. If not, goes back to the default routine.

  • os.environ.pop() and os.environ.clear() now call unsetenv() for a correct behavior.

  • Added support for FreeBSD 8.

  • Added mp4 to mimetypes.py.

  • Various fixes in the bsddb module (like bsddb.dbshelve using the highest pickle protocol and more).

  • Fixed marshal’s incorrect handling of subclasses of builtin types.

  • Added set/frozenset’s isdisjoint(): returns True if two sets have a null intersection.

  • Added getter, setter, deleter methods to properties that can be used as decorators to create fully-populated properties.

[code lang="python"] class C: foo = property(doc=”hello”) @foo.getter def foo(self): return self._foo @foo.setter def foo(self, value): self._foo = abs(value) @foo.deleter def foo(self): del self._foo c = C() assert C.foo.doc == “hello” assert not hasattr(c, “foo”) c.foo = -42 assert c.foo == 42 del c.foo assert not hasattr(c, “foo”) [/code]

[code lang="python"] Python 2.6a0 (trunk:59170M, Nov 24 2007, 15:06:35)

a = “pippoplutarca” a.find(’t', None, None)
8

Python 2.5.1 (r251:54869, Apr 18 2007, 22:08:04)

a = “pippoplutarca” a.find(’t', None, None) Traceback (most recent call last): File ““, line 1, in TypeError: slice indices must be integers or None or have an index method [/code]

  • Directories and zipfiles containing a _ main _.py file can now be directly executed by passing their name to the interpreter. The directory/zipfile is automatically inserted as the first entry in sys.path.

  • Abstract base classes have been backported to Python 2.6.

  • Python 2.6 is now compilable with Visual Studio 2008.

  • Major change in the internal structure of the Decimal number: now it does not store the mantissa as a tuple of numbers, but as a string. This avoids a lot of conversions, and achieves a speedup of 40%. The API remains intact.

Updates from Python SVN, Part 17

  • decimal module:

    • There’s a bunch of is_* methods (like is_signed()) in Decimal class returning a boolean value.
    • Added an internal class to store the digits of log(10), so that they can be made available when necessary without recomputing.
  • enumerate() is no longer bounded to using sequences shorter than LONG_MAX. Formerly, it raised an OverflowError. Now, automatically shifts from ints to longs.

  • itertools.count() is no longer bounded to LONG_MAX. Formerly, it raised an OverflowError. Now, automatically shifts from ints to longs.

  • collections module:

    • NamedTuple became named_tuple.
    • named_tuple field specification can be a string or a list of strings.
    • _ _ asdict _ _() have been added to convert a named tuple instance to dict.
    • Add maxlen support to deque().
  • Splits Modules/_bsddb.c up into bsddb.h and _bsddb.c and adds a C API object available as bsddb.db.api.

Updates from Python SVN, Part 16

  • Added utility function to ssl module, get_server_certificate, to wrap up the several things to be done to pull a certificate from a remote server.

  • Optimize performance of cgi.FieldStorage operations.

  • Added os.environ.clear() method: will unset all the environment variables.

Updates from Python SVN, Part 15

  • Added support for linking the bsddb module against BerkeleyDB 4.5.x and 4.6.x.

  • Added set_completion_display_matches_hook and get_completion_type to readline module.

  • Added a c_longdouble type to the ctypes module.

  • abc.py and isinstance/issubclass overloading have been backported. See PEP 3119 for details about Abstract Base Classes.

  • generator’s throw() doesn’t support string exceptions anymore:

[code lang="python"] Python 2.5.1 (r251:54869, Apr 18 2007, 22:08:04) [GCC 4.0.1 (Apple Computer, Inc. build 5367)] on darwin Type “help”, “copyright”, “credits” or “license” for more information.

def f(): yield 1 … a = f() a.throw(”error”) Traceback (most recent call last): File ““, line 1, in File ““, line 1, in f error

Python 2.6a0 (trunk:58159M, Sep 15 2007, 13:43:25) [GCC 4.0.1 (Apple Computer, Inc. build 5367)] on darwin Type “help”, “copyright”, “credits” or “license” for more information.

def f(): yield 1 … a = f() a.throw(”error”) Traceback (most recent call last): File ““, line 1, in TypeError: exceptions must be classes, or instances, not str [/code]

Updates from Python SVN, Part 14

Some news from the Python trunk:

  • Server-side SSL support and certificate verification. See the doc.

  • The functools module now provides reduce, for forward compatibility with Python 3000.

  • Extended slicing support in builtin types and classes has been improved:

    • Specialcase extended slices that amount to a shallow copy the same way as is done for simple slices, in the tuple, string and unicode case.

    • Specialcase step-1 extended slices to optimize the common case for all involved types.

    • For lists, allow extended slice assignment of differing lengths as long as the step is 1. (previously, ‘l[:2:1] = []‘ failed even though ‘l[:2] = []‘ and ‘l[:2:None] = []‘ do not)

    • Implement extended slicing for buffer, array, structseq, mmap and UserString.UserString.

    • Implement slice-object support (but not non-step-1 slice assignment) for UserString.MutableString.

  • socket.ssl deprecated; use new ssl module instead.

  • httplib.FakeSocket is deprecated.

Updates from Python SVN, Part 13

  • New codecs for UTF-32, UTF-32-LE and UTF-32-BE are in place.

  • EUC-KR codec now handles the cheot-ga-keut composed make-up hangul syllables.

  • BeOS is no longer supported (remember that AtheOS, Win9x and WinME as well will be no longer supported in Python 2.6, see PEP 11 for the details).

  • uuid creation is now threadsafe.

Updates from Python SVN, Part 12

Python 2.6 documentation will be in the reST format. I, personally, am really happy that LaTeX doc is gone.

See for example the documentation of the sys module

Updates from Python SVN, Part 11

Updates from Python SVN, Part 10

TarFile.add() has a new exclude parameter. You provide a predicate function to determine what goes in and what doesn’t.

Next entries »