Skip to content

Commit f330465

Browse files
feat: add dedicated questions namespace and separate from issues
Introduces kili.questions namespace with dedicated methods for question management. Refactors issues namespace to explicitly filter for issue type, ensuring clear separation between issues and questions in the domain API.
1 parent 6e8f185 commit f330465

File tree

4 files changed

+585
-14
lines changed

4 files changed

+585
-14
lines changed

src/kili/client_domain.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
LabelsNamespace,
1717
OrganizationsNamespace,
1818
ProjectsNamespace,
19+
QuestionsNamespace,
1920
StoragesNamespace,
2021
TagsNamespace,
2122
UsersNamespace,
@@ -208,6 +209,24 @@ def issues(self) -> "IssuesNamespace":
208209

209210
return IssuesNamespace(self.legacy_client, self.legacy_client.kili_api_gateway)
210211

212+
@cached_property
213+
def questions(self) -> "QuestionsNamespace":
214+
"""Get the questions domain namespace.
215+
216+
Returns:
217+
QuestionsNamespace: Questions domain namespace with lazy loading
218+
219+
Examples:
220+
```python
221+
kili = Kili()
222+
# Namespace is instantiated on first access
223+
questions = kili.questions
224+
```
225+
"""
226+
from kili.domain_api import QuestionsNamespace # pylint: disable=import-outside-toplevel
227+
228+
return QuestionsNamespace(self.legacy_client, self.legacy_client.kili_api_gateway)
229+
211230
@cached_property
212231
def tags(self) -> "TagsNamespace":
213232
"""Get the tags domain namespace.

src/kili/domain_api/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from .organizations import OrganizationsNamespace
1313
from .plugins import PluginsNamespace
1414
from .projects import ProjectsNamespace
15+
from .questions import QuestionsNamespace
1516
from .storages import StoragesNamespace
1617
from .tags import TagsNamespace
1718
from .users import UsersNamespace
@@ -25,6 +26,7 @@
2526
"OrganizationsNamespace",
2627
"PluginsNamespace",
2728
"ProjectsNamespace",
29+
"QuestionsNamespace",
2830
"StoragesNamespace",
2931
"TagsNamespace",
3032
"UsersNamespace",

src/kili/domain_api/issues.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
from typeguard import typechecked
1111

12-
from kili.domain.issue import IssueId, IssueStatus, IssueType
12+
from kili.domain.issue import IssueId, IssueStatus
1313
from kili.domain.label import LabelId
1414
from kili.domain.project import ProjectId
1515
from kili.domain.types import ListOrTuple
@@ -28,13 +28,11 @@ class IssueFilter(TypedDict, total=False):
2828
asset_id: Id of the asset whose returned issues are associated to.
2929
asset_id_in: List of Ids of assets whose returned issues are associated to.
3030
status: Status of the issues to return (e.g., 'OPEN', 'SOLVED', 'CANCELLED').
31-
issue_type: Type of the issue to return. An issue object both represents issues and questions in the app.
3231
"""
3332

3433
asset_id: Optional[str]
3534
asset_id_in: Optional[List[str]]
3635
status: Optional[IssueStatus]
37-
issue_type: Optional[IssueType]
3836

3937

4038
class IssuesNamespace(DomainNamespace):
@@ -99,10 +97,8 @@ def list(
9997
) -> List[Dict]:
10098
"""Get a list of issues that match a set of criteria.
10199
102-
!!! Info "Issues or Questions"
103-
An `Issue` object both represent an issue and a question in the app.
104-
To create them, two different methods are provided: `create_issues` and `create_questions`.
105-
However to query issues and questions, we currently provide this unique method that retrieves both of them.
100+
!!! Info "Issues vs Questions"
101+
This method returns only issues (type='ISSUE'). For questions, use `kili.questions.list()` instead.
106102
107103
Args:
108104
project_id: Project ID the issue belongs to.
@@ -134,7 +130,9 @@ def list(
134130
... filter={"status": "OPEN"}
135131
... )
136132
"""
137-
filter_kwargs = filter or {}
133+
filter_kwargs: Dict[str, Any] = dict(filter or {})
134+
# Force issue_type to ISSUE
135+
filter_kwargs["issue_type"] = "ISSUE"
138136
return self.client.issues(
139137
as_generator=False,
140138
disable_tqdm=disable_tqdm,
@@ -163,10 +161,9 @@ def list_as_generator(
163161
) -> Generator[Dict, None, None]:
164162
"""Get a generator of issues that match a set of criteria.
165163
166-
!!! Info "Issues or Questions"
167-
An `Issue` object both represent an issue and a question in the app.
168-
To create them, two different methods are provided: `create_issues` and `create_questions`.
169-
However to query issues and questions, we currently provide this unique method that retrieves both of them.
164+
!!! Info "Issues vs Questions"
165+
This method returns only issues (type='ISSUE'). For questions, use
166+
`kili.questions.list_as_generator()` instead.
170167
171168
Args:
172169
project_id: Project ID the issue belongs to.
@@ -193,7 +190,9 @@ def list_as_generator(
193190
... ):
194191
... print(issue["id"])
195192
"""
196-
filter_kwargs = filter or {}
193+
filter_kwargs: Dict[str, Any] = dict(filter or {})
194+
# Force issue_type to ISSUE
195+
filter_kwargs["issue_type"] = "ISSUE"
197196
return self.client.issues(
198197
as_generator=True,
199198
disable_tqdm=disable_tqdm,
@@ -225,7 +224,9 @@ def count(self, project_id: str, filter: Optional[IssueFilter] = None) -> int:
225224
... filter={"asset_id_in": ["asset_1", "asset_2"], "status": "OPEN"}
226225
... )
227226
"""
228-
filter_kwargs = filter or {}
227+
filter_kwargs: Dict[str, Any] = dict(filter or {})
228+
# Force issue_type to ISSUE
229+
filter_kwargs["issue_type"] = "ISSUE"
229230
return self.client.count_issues(
230231
project_id=project_id,
231232
**filter_kwargs,

0 commit comments

Comments
 (0)