injecting "set" into 2.3's builtins?

John Machin sjmachin at lexicon.net
Fri Mar 11 19:01:38 EST 2005


and-google at doxdesk.com wrote:
> Skip Montanaro wrote:
>
> > I use sets a lot in my Python 2.3 code at work and have been using
> > this hideous import to make the future move to 2.4's set type
> > transparent:
>
> >     try:
> >         x = set
>
> (Surely just 'set' on its own is sufficient? This avoids the ugly
else
> clause.)
>
> >     __builtin__.set = sets.Set
>
> > I'm wondering if others have tried it. If so, did it cause any
> > problems?
>
> I don't know of any specific case where it would cause problems but
I'd
> be very wary of this; certainly doing the same with True and False
has
> caused problems in the past. A module might sniff for 'set' and
assume
> it is running on 2.4 if it sees it, with unpredictable results if it
> relies on any other 2.4 behaviour.

Aarrgghh! When there's a documented API (sys.version_info) for
determining the version, such a module (and it's author) could be
charitably described as "broken". I can't imagine there are any on
Skip's site :-)




More information about the Python-list mailing list