Anselm Kruis added the comment:

I created a small *.pth to monkey patch collections.py until 2.7.6 gets 
released. Maybe this is useful for someone else. Therefore I attach it here.

The pth file runs the following code during Python startup:

import collections
def _fix_issue_18015(collections):
    try:
        template = collections._class_template
    except AttributeError:
        # prior to 2.7.4 _class_template didn't exists
        return
    if not isinstance(template, basestring):
        return  # strange
    if "__dict__" in template or "__getstate__" in template:
        return  # already patched
    lines = template.splitlines()
    indent = -1
    for i,l in enumerate(lines):
        if indent < 0:
            indent = l.find('def _asdict')
            continue
        if l.startswith(' '*indent + 'def '):
            lines.insert(i, ' '*indent + 'def __getstate__(self): pass')
            lines.insert(i, ' '*indent + '__dict__ = _property(_asdict)')
            break
    collections._class_template = '''\n'''.join(lines)
_fix_issue_18015(collections)

----------
Added file: http://bugs.python.org/file30338/fix_python_275_issue18015.pth

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue18015>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to