we need this method, and the following bad behavior goes against python's design:
from pywikibot import * Link.__hash__
<slot wrapper '__hash__' of 'object' objects>
Link.__eq__
Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: type object 'Link' has no attribute '__eq__'
Link.__cmp__
<unbound method Link.__cmp__>
hash(Link('1'))
26872464
hash(Link('1'))
26872400
hash(Link('1'))
26872464
Link('1')==Link('1')
Found 1 wikipedia:zh processes running, including this one. True
hash(Link('1'))==hash(Link('1'))
False
Oh, interesting.
For those wondering, this is related to Link in pywikibot.page (rewrite branch).
What were you hashing Link objects for?
What about:
Index: pywikibot/page.py =================================================================== --- pywikibot/page.py (revision 6639) +++ pywikibot/page.py (working copy) @@ -1945,7 +1945,13 @@ return cmp(self.namespace, other.namespace) return cmp(self.title, other.title)
+ def __unicode__(self): + return self.astext()
+ def __hash__(self): + return hash(self.astext()) + + # Utility functions for parsing page titles
def html2unicode(text, ignore = []):
I believe that it should be correct, knowing that astext() should not change from one instance to another.
already committed?
and there are some problems else:
1. pywikibot.Page(pywikibot.Site(), 'talk:1').get() this raises pywikibot.exceptions.Error
2. (maybe a little bit difficult) can you add transaction support for pywikibot?
On 4/20/09, Nicolas Dumazet nicdumz@gmail.com wrote:
Oh, interesting.
For those wondering, this is related to Link in pywikibot.page (rewrite branch).
What were you hashing Link objects for?
What about:
Index: pywikibot/page.py
--- pywikibot/page.py (revision 6639) +++ pywikibot/page.py (working copy) @@ -1945,7 +1945,13 @@ return cmp(self.namespace, other.namespace) return cmp(self.title, other.title)
def __unicode__(self):
return self.astext()
def __hash__(self):
return hash(self.astext())
# Utility functions for parsing page titles
def html2unicode(text, ignore = []):
I believe that it should be correct, knowing that astext() should not change from one instance to another.
-- Nicolas Dumazet — NicDumZ [ nɪk.d̪ymz ]
Pywikipedia-l mailing list Pywikipedia-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/pywikipedia-l
i needed hash to use Link objects as keys of dict.
On 4/20/09, Liangent liangent@gmail.com wrote:
already committed?
and there are some problems else:
pywikibot.Page(pywikibot.Site(), 'talk:1').get() this raises pywikibot.exceptions.Error
(maybe a little bit difficult) can you add transaction support for pywikibot?
On 4/20/09, Nicolas Dumazet nicdumz@gmail.com wrote:
Oh, interesting.
For those wondering, this is related to Link in pywikibot.page (rewrite branch).
What were you hashing Link objects for?
What about:
Index: pywikibot/page.py
--- pywikibot/page.py (revision 6639) +++ pywikibot/page.py (working copy) @@ -1945,7 +1945,13 @@ return cmp(self.namespace, other.namespace) return cmp(self.title, other.title)
def __unicode__(self):
return self.astext()
def __hash__(self):
return hash(self.astext())
# Utility functions for parsing page titles
def html2unicode(text, ignore = []):
I believe that it should be correct, knowing that astext() should not change from one instance to another.
-- Nicolas Dumazet — NicDumZ [ nɪk.d̪ymz ]
Pywikipedia-l mailing list Pywikipedia-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/pywikipedia-l
btw, do other objects have a correct __hash__ method now?
On 4/20/09, Liangent liangent@gmail.com wrote:
i needed hash to use Link objects as keys of dict.
On 4/20/09, Liangent liangent@gmail.com wrote:
already committed?
and there are some problems else:
pywikibot.Page(pywikibot.Site(), 'talk:1').get() this raises pywikibot.exceptions.Error
(maybe a little bit difficult) can you add transaction support for pywikibot?
On 4/20/09, Nicolas Dumazet nicdumz@gmail.com wrote:
Oh, interesting.
For those wondering, this is related to Link in pywikibot.page (rewrite branch).
What were you hashing Link objects for?
What about:
Index: pywikibot/page.py
--- pywikibot/page.py (revision 6639) +++ pywikibot/page.py (working copy) @@ -1945,7 +1945,13 @@ return cmp(self.namespace, other.namespace) return cmp(self.title, other.title)
def __unicode__(self):
return self.astext()
def __hash__(self):
return hash(self.astext())
# Utility functions for parsing page titles
def html2unicode(text, ignore = []):
I believe that it should be correct, knowing that astext() should not change from one instance to another.
-- Nicolas Dumazet — NicDumZ [ nɪk.d̪ymz ]
Pywikipedia-l mailing list Pywikipedia-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/pywikipedia-l
pywikipedia-l@lists.wikimedia.org