Repository: pycontribs/jira

Issue:
TypeError: ResultList object is not an iterator
The `ResultList` class doesn't support iteration. It seems like it should because the concept is a List.

When executing the following code:

```python
jira = JIRA('https://jira.atlassian.net', auth=(username, password))

search_issues = jira.search_issues('updated >= "2018-05-22 11:30"')

next(search_issues)
```

This Exception is raised:

```
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-15-35388d9445e9> in <module>()
----> 1 next(search_issues)

TypeError: ResultList object is not an iterator
```

For system and version issues, I'm using:

-  jira==1.0.15
- OSX 10.13.3
- python 2.7

I'd be comfortable submitting a pull request if `ResultList` should be an `iterator`.

Please advise.

Thanks

TypeError: ResultList object is not an iterator
The `ResultList` class doesn't support iteration. It seems like it should because the concept is a List.

When executing the following code:

```python
jira = JIRA('https://jira.atlassian.net', auth=(username, password))

search_issues = jira.search_issues('updated >= "2018-05-22 11:30"')

next(search_issues)
```

This Exception is raised:

```
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-15-35388d9445e9> in <module>()
----> 1 next(search_issues)

TypeError: ResultList object is not an iterator
```

For system and version issues, I'm using:

-  jira==1.0.15
- OSX 10.13.3
- python 2.7

I'd be comfortable submitting a pull request if `ResultList` should be an `iterator`.

Please advise.

Thanks



Discussion:
PRs are always welcome, please add tests also.
Ok, I will look into submitting a PR. Thanks
Indeed, it should be an iterator, no matter what.
PRs are always welcome, please add tests also.
Ok, I will look into submitting a PR. Thanks
Indeed, it should be an iterator, no matter what.

Resolving patch:
diff --git a/jira/client.py b/jira/client.py
--- a/jira/client.py
+++ b/jira/client.py
@@ -147,7 +147,7 @@ def _field_worker(fields=None, **fieldargs):
 
 class ResultList(list):
 
-    def __init__(self, iterable=None, _startAt=None, _maxResults=None, _total=None, _isLast=None):
+    def __init__(self, iterable=None, _startAt=0, _maxResults=0, _total=0, _isLast=None):
         if iterable is not None:
             list.__init__(self, iterable)
         else:
@@ -159,6 +159,18 @@ def __init__(self, iterable=None, _startAt=None, _maxResults=None, _total=None,
         self.isLast = _isLast
         self.total = _total
 
+        self.iterable = iterable or []
+        self.current = self.startAt
+
+    def __next__(self):
+        self.current += 1
+        if self.current > self.total:
+            raise StopIteration
+        else:
+            return self.iterable[self.current - 1]
+    # Python 2 and 3 compat
+    next = __next__
+
 
 class QshGenerator(object):
 


Test patch:
diff --git a/tests/test_client.py b/tests/test_client.py
--- a/tests/test_client.py
+++ b/tests/test_client.py
@@ -127,3 +127,31 @@ def test_template_list():
     assert [t['name'] for t in template_list] == ["Scrum software development", "Kanban software development", "Basic software development",
                                                   "Basic Service Desk", "IT Service Desk", "Task management", "Project management",
                                                   "Process management"]
+
+
+def test_result_list():
+    iterable = [2, 3]
+    startAt = 0
+    maxResults = 50
+    total = 2
+
+    results = jira.client.ResultList(iterable, startAt, maxResults, total)
+
+    for idx, result in enumerate(results):
+        assert results[idx] == iterable[idx]
+
+    assert next(results) == iterable[0]
+    assert next(results) == iterable[1]
+
+    with pytest.raises(StopIteration):
+        next(results)
+
+
+def test_result_list_if_empty():
+    results = jira.client.ResultList()
+
+    for r in results:
+        raise AssertionError("`results` should be empty")
+
+    with pytest.raises(StopIteration):
+        next(results)