mmueller / supybot-git

A Git plugin for Supybot (a Python IRC bot)
45 stars 24 forks source link

'listreverseiterator' object is unsubscriptable (API_VERSION==1) #5

Closed iam-TJ closed 11 years ago

iam-TJ commented 11 years ago

Having just installed the plug-in and configured it with one repository - a local clone of linux.git -I'm seeing this error repeatedly during _poll() operations. (Additional traceback added to help diagnose):

ERROR 2012-10-27T12:20:25 supybot Git: Exception in _poll repository linux: 'listreverseiterator' object is unsubscriptable ERROR 2012-10-27T12:20:25 supybot Git: Traceback (most recent call last): File "/home/mooc/supybot/plugins/Git/plugin.py", line 375, in _poll commits = repository.get_new_commits()[::-1] TypeError: 'listreverseiterator' object is unsubscriptable

platform.python_version() '2.6.5' git.version '0.1.6'

So API_VERSION should be 1.

The code-path is:

Repository.get_new_commits() result = self.repo.commits_between(self.last_commit, self.branch) return reversed(Commit.find_all(self, "%s..%s" % (frm, to)))

This will return a class reversed() object which is a reverse iterator and cannot be subscripted:

myList = [1,2,3,4,5] revList = reversed(myList) myList [1, 2, 3, 4, 5] revList <listreverseiterator object at 0xb721328c> myList[::-1] [5, 4, 3, 2, 1] revList[::-1] Traceback (most recent call last): File "", line 1, in TypeError: 'listreverseiterator' object is unsubscriptable

The fix is to convert the reverseiterator to a list:

def get_new_commits(self):
    if API_VERSION == 1:
        result = list(self.repo.commits_between(self.last_commit, self.branch))
samrg472 commented 11 years ago

That commit works for me. No more issues now.

mmueller commented 11 years ago

Thanks for the report and patch, TJ! Can you submit it as a pull request?

mmueller commented 11 years ago

Fixed in pull request #6. Thanks TJ!