Skip to content

Commit 10afa59

Browse files
StealthiiWojtini
authored andcommitted
Provide overload type hints for search_issues variants (#1861)
1 parent 07b84bf commit 10afa59

File tree

3 files changed

+39
-9
lines changed

3 files changed

+39
-9
lines changed

examples/auth.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from __future__ import annotations
44

55
from collections import Counter
6-
from typing import cast
76

87
from jira import JIRA
98
from jira.client import ResultList
@@ -25,9 +24,7 @@
2524
props = jira.application_properties()
2625

2726
# Find all issues reported by the admin
28-
# Note: we cast() for mypy's benefit, as search_issues can also return the raw json !
29-
# This is if the following argument is used: `json_result=True`
30-
issues = cast(ResultList[Issue], jira.search_issues("assignee=admin"))
27+
issues: ResultList[Issue] = jira.search_issues("assignee=admin")
3128

3229
# Find the top three projects containing issues reported by admin
3330
top_three = Counter([issue.fields.project.key for issue in issues]).most_common(3)

jira/client.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3483,6 +3483,22 @@ def resolution(self, id: str) -> Resolution:
34833483

34843484
# Search
34853485

3486+
@overload
3487+
def search_issues(
3488+
self,
3489+
jql_str: str,
3490+
startAt: int = 0,
3491+
maxResults: int = 50,
3492+
validate_query: bool = True,
3493+
fields: str | list[str] | None = "*all",
3494+
expand: str | None = None,
3495+
properties: str | None = None,
3496+
*,
3497+
json_result: Literal[False] = False,
3498+
use_post: bool = False,
3499+
) -> ResultList[Issue]: ...
3500+
3501+
@overload
34863502
def search_issues(
34873503
self,
34883504
jql_str: str,
@@ -3492,6 +3508,21 @@ def search_issues(
34923508
fields: str | list[str] | None = "*all",
34933509
expand: str | None = None,
34943510
properties: str | None = None,
3511+
*,
3512+
json_result: Literal[True],
3513+
use_post: bool = False,
3514+
) -> dict[str, Any]: ...
3515+
3516+
def search_issues(
3517+
self,
3518+
jql_str: str,
3519+
startAt: int = 0,
3520+
maxResults: int = 50,
3521+
validate_query: bool = True,
3522+
fields: str | list[str] | None = "*all",
3523+
expand: str | None = None,
3524+
properties: str | None = None,
3525+
*,
34953526
json_result: bool = False,
34963527
use_post: bool = False,
34973528
) -> dict[str, Any] | ResultList[Issue]:

tests/tests.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -231,19 +231,24 @@ def setUp(self):
231231

232232
def test_search_issues(self):
233233
issues = self.jira.search_issues(f"project={self.project_b}")
234-
issues = cast(ResultList[Issue], issues)
235234
self.assertLessEqual(len(issues), 50) # default maxResults
236235
for issue in issues:
237236
self.assertTrue(issue.key.startswith(self.project_b))
238237

238+
def test_search_issues_json(self):
239+
result = self.jira.search_issues(f"project={self.project_b}", json_result=True)
240+
issues = result["issues"]
241+
self.assertLessEqual(len(issues), 50) # default maxResults
242+
for issue in issues:
243+
self.assertTrue(issue["key"].startswith(self.project_b))
244+
239245
def test_search_issues_async(self):
240246
original_val = self.jira._options["async"]
241247
try:
242248
self.jira._options["async"] = True
243249
issues = self.jira.search_issues(
244250
f"project={self.project_b}", maxResults=False
245251
)
246-
issues = cast(ResultList[Issue], issues)
247252
self.assertEqual(len(issues), issues.total)
248253
for issue in issues:
249254
self.assertTrue(issue.key.startswith(self.project_b))
@@ -263,7 +268,6 @@ def test_search_issues_startat(self):
263268

264269
def test_search_issues_field_limiting(self):
265270
issues = self.jira.search_issues(f"key={self.issue}", fields="summary,comment")
266-
issues = cast(ResultList[Issue], issues)
267271
self.assertTrue(hasattr(issues[0].fields, "summary"))
268272
self.assertTrue(hasattr(issues[0].fields, "comment"))
269273
self.assertFalse(hasattr(issues[0].fields, "reporter"))
@@ -292,7 +296,6 @@ def test_search_issues_fields_translating(self):
292296

293297
def test_search_issues_expand(self):
294298
issues = self.jira.search_issues(f"key={self.issue}", expand="changelog")
295-
issues = cast(ResultList[Issue], issues)
296299
# self.assertTrue(hasattr(issues[0], 'names'))
297300
self.assertEqual(len(issues), 1)
298301
self.assertFalse(hasattr(issues[0], "editmeta"))
@@ -304,7 +307,6 @@ def test_search_issues_use_post(self):
304307
with pytest.raises(JIRAError):
305308
self.jira.search_issues(long_jql)
306309
issues = self.jira.search_issues(long_jql, use_post=True)
307-
issues = cast(ResultList[Issue], issues)
308310
self.assertEqual(len(issues), 1)
309311
self.assertEqual(issues[0].key, self.issue)
310312

0 commit comments

Comments
 (0)