http://www.mediawiki.org/wiki/Special:Code/pywikipedia/11276
Revision: 11276 Author: xqt Date: 2013-03-25 23:55:40 +0000 (Mon, 25 Mar 2013) Log Message: ----------- Override _sites cache if instance does not match. This will solve the following:
import pwb import pywikibot as wp s = wp.Site('wikidata', 'wikidata') s
Site("wikidata", "wikidata")
s = wp.Site('wikidata', 'wikidata', interface='DataSite') s
DataSite("wikidata", "wikidata")
here the second instantation returns the right class whereas the previous cached object would be Site("wikidata", "wikidata")
Modified Paths: -------------- branches/rewrite/pywikibot/__init__.py
Modified: branches/rewrite/pywikibot/__init__.py =================================================================== --- branches/rewrite/pywikibot/__init__.py 2013-03-25 19:09:07 UTC (rev 11275) +++ branches/rewrite/pywikibot/__init__.py 2013-03-25 23:55:40 UTC (rev 11276) @@ -168,7 +168,7 @@ except ImportError: raise ValueError("Invalid interface name '%(interface)s'" % locals()) key = '%s:%s:%s' % (fam, code, user) - if not key in _sites: + if not key in _sites or not isinstance(_sites[key], __Site): _sites[key] = __Site(code=code, fam=fam, user=user, sysop=sysop) pywikibot.debug(u"Instantiating Site object '%(site)s'" % {'site': _sites[key]}, _logger)
pywikipedia-svn@lists.wikimedia.org