Donate Share

MySQL for Python

Tracker: Bugs

5 Python 2.6 deprecates sets module - ID: 2156977
Last Update: Comment added ( rayvd )

As of python 2.6, the sets module is deprecated. This is currently used in
MySQLdb/__init__.py and MySQLdb/converters.py - on both the 1.2 branch and
the trunk.

Fixing the ImmutableSet usage is fairly easy. Currently:

from sets import ImmutableSet

class DBAPISet(ImmutableSet):
...

I think the new built in frozenset (added in python 2.4) should be used
instead. Suggested short term fix to preserve compatibility for older
versions of python:

try :
ImmutableSet = frozenset
except NameError:
from sets import ImmutableSet

class DBAPISet(ImmutableSet):
...

Longer term fix would be something like:

try:
frozenset = frozenset
except NameError:
from sets import ImmutableSet as frozenset

class DBAPISet(frozenset):
...

However, I am not sure off hand what to use to replace sets.BaseSet with.


Peter ( maubp ) - 2008-10-10 09:29

5

Open

Fixed

Andy Dustman

MySQLdb

None

Public


Comments ( 5 )

Date: 2009-06-25 17:21
Sender: rayvd

Will a 1.2.3 release (or other) be made incorporating this change?


Date: 2008-11-17 19:28
Sender: bkline

Works on Python 2.6. Any idea when this will make it into a non-beta
release?

Also, while working with this bug, I noticed that the ez_setup part of the
installation scripts is broken, as it's trying to pull down versions of
distutils from cheeseshop which don't exist. I fixed that by hand, but it
probably be fixed in the distro. Want a separate bug report for this?


Date: 2008-10-18 00:16
Sender: adustmanProject AdminAccepting Donations

This one now ought to be fixed as well.


Date: 2008-10-17 09:10
Sender: maubp

The MySQLdb/__init__.py update works for me on Python 2.6 (using MySQLdb
1.2.2 plus MySQLdb/__init__.py revision 554).

That leaves MySQLdb/converters.py still using the deprecated sets module.
When I originally filed this bug I have noticed you imported BaseSet,

from sets import BaseSet, Set

However, you are not actually using BaseSet, but just Set in the Str2Set
function. This means a simple fix is possible:

from sets import BaseSet, Set
#more code here
def Str2Set(s):
....return Set([ i for i in s.split(',') if i ])

becomes:

try :
....set
except NameError:
....from sets import Set as set
#more code here
def Str2Set(s):
....return set([ i for i in s.split(',') if i ])

[I've used periods to indicate the indentation, as spaces seemed to get
lost last time]

I haven't done this, but it would be wise to also test on Python 2.3 where
the built in set/frozen set are not available, to cover the other branch of
the try/except.

Thanks,

Peter


Date: 2008-10-17 00:45
Sender: adustmanProject AdminAccepting Donations

Fixed in 1.2 branch. Only tested for Python 2.5.


Attached File

No Files Currently Attached

Change ( 1 )

Field Old Value Date By
resolution_id None 2008-10-17 00:45 adustman