December 27, 2007 at 4:21 pm · tags: Python Python SVN
Here we are with another update from Python 2.x SVN.
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().
November 24, 2007 at 4:58 pm · tags: Python Python SVN
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.
October 13, 2007 at 1:10 pm · tags: Python Python SVN
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.
September 29, 2007 at 2:45 pm · tags: Python Python SVN
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.
September 16, 2007 at 10:51 pm · tags: Python Python SVN
[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]
September 1, 2007 at 5:48 pm · tags: Python Python SVN
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.
August 24, 2007 at 11:41 pm · tags: Python Python SVN
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.
August 16, 2007 at 11:52 am · tags: Python Python SVN
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
August 5, 2007 at 10:49 pm · tags: Python Python SVN
July 18, 2007 at 11:48 am · tags: Python Python SVN
TarFile.add() has a new exclude parameter. You provide a predicate function to determine what goes in and what doesn’t.
Next entries »