Skip to content

Commit

Permalink
Revert breaking change for python3.8 (collections.abc.AsyncIterator i…
Browse files Browse the repository at this point in the history
…s not subscriptable)
  • Loading branch information
sim0nx committed Sep 25, 2023
1 parent a884055 commit 0c50c5f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file.

This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [v3.1.2], 2023-09-25
### Fixes
- Revert breaking change for python3.8 (collections.abc.AsyncIterator is not subscriptable).

## [v3.1.1], 2023-09-25
### Fixes
- In AsyncRt, instead of returning sequences, return AsyncIterators.
Expand Down
6 changes: 6 additions & 0 deletions doc/changelog.rst
@@ -1,6 +1,12 @@
Change Log
==========

Version 3.1.2 (2023-09-25)
----------------------------
Fixes
^^^^^
- Revert breaking change for python3.8 (collections.abc.AsyncIterator is not subscriptable).

Version 3.1.1 (2023-09-25)
----------------------------
Fixes
Expand Down
28 changes: 17 additions & 11 deletions rt/rest2.py
Expand Up @@ -5,7 +5,7 @@
"""

import base64
import collections
import collections.abc
import dataclasses
import datetime
import json
Expand Down Expand Up @@ -1632,7 +1632,7 @@ async def __paged_request(self,
page: int = 1,
per_page: int = 20,
recurse: bool = True,
) -> collections.abc.AsyncIterator[typing.Dict[str, typing.Any]]:
) -> collections.abc.AsyncIterator:
""" Request using pagination for :term:`API`.
:param selector: End part of URL which completes self.url parameter
Expand All @@ -1643,7 +1643,7 @@ async def __paged_request(self,
:param per_page: Number of results per page to get.
:param recurse: Set on the initial call in order to retrieve all pages recursively.
:returns: dict
:returns: collections.abc.AsyncIterator[typing.Dict[str, typing.Any]]
:raises AuthorizationError: In case that request is called without previous
login or login attempt failed.
:raises ConnectionError: In case of connection error.
Expand Down Expand Up @@ -1733,7 +1733,7 @@ async def __get_url(self, url: str) -> typing.Dict[str, typing.Any]:

return res

async def new_correspondence(self, queue: typing.Optional[typing.Union[str, object]] = None) -> collections.abc.AsyncIterator[dict]:
async def new_correspondence(self, queue: typing.Optional[typing.Union[str, object]] = None) -> collections.abc.AsyncIterator:
""" Obtains tickets changed by other users than the system one.
:param queue: Queue where to search
Expand All @@ -1742,10 +1742,11 @@ async def new_correspondence(self, queue: typing.Optional[typing.Union[str, obje
the system one, ordered in decreasing order by LastUpdated.
Each ticket is dictionary, the same as in
:py:meth:`~Rt.get_ticket`.
collections.abc.AsyncIterator[dict]
"""
return self.search(queue=queue, order='-LastUpdated')

async def last_updated(self, since: str, queue: typing.Optional[str] = None) -> collections.abc.AsyncIterator[dict]:
async def last_updated(self, since: str, queue: typing.Optional[str] = None) -> collections.abc.AsyncIterator:
""" Obtains tickets changed after given date.
:param since: Date as string in form '2011-02-24'
Expand All @@ -1755,6 +1756,7 @@ async def last_updated(self, since: str, queue: typing.Optional[str] = None) ->
*since* ordered in decreasing order by LastUpdated.
Each ticket is a dictionary, the same as in
:py:meth:`~Rt.get_ticket`.
collections.abc.AsyncIterator[dict]
:raises InvalidUseError: If the specified date is of an unsupported format.
"""
Expand All @@ -1781,7 +1783,7 @@ def __validate_date(cls, _date: str) -> bool:
return False

async def search(self, queue: typing.Optional[typing.Union[str, object]] = None, order: typing.Optional[str] = None,
raw_query: typing.Optional[str] = None, query_format: str = 'l', **kwargs: typing.Any) -> collections.abc.AsyncIterator[dict]:
raw_query: typing.Optional[str] = None, query_format: str = 'l', **kwargs: typing.Any) -> collections.abc.AsyncIterator:
r""" Search arbitrary needles in given fields and queue.
Example::
Expand Down Expand Up @@ -1831,6 +1833,7 @@ async def search(self, queue: typing.Optional[typing.Union[str, object]] = None,
:returns: Iterator over matching tickets. Each ticket is the same dictionary
as in :py:meth:`~Rt.get_ticket`.
collections.abc.AsyncIterator[dict]
:raises: UnexpectedMessageFormatError: Unexpected format of returned message.
InvalidQueryError: If raw query is malformed
"""
Expand Down Expand Up @@ -2012,12 +2015,13 @@ async def edit_ticket(self, ticket_id: typing.Union[str, int], **kwargs: typing.

return bool(msg[0])

async def get_ticket_history(self, ticket_id: typing.Union[str, int]) -> collections.abc.AsyncIterator[typing.Dict[str, typing.Any]]:
async def get_ticket_history(self, ticket_id: typing.Union[str, int]) -> collections.abc.AsyncIterator:
""" Get set of short history items
:param ticket_id: ID of ticket
:returns: Iterator of history items ordered increasingly by time of event.
Each history item is a tuple containing (id, Description).
collections.abc.AsyncIterator[typing.Dict[str, typing.Any]]
"""
async for transaction in self.__paged_request(f'ticket/{ticket_id}/history',
params={'fields': 'Type,Creator,Created,Description,_hyperlinks',
Expand Down Expand Up @@ -2154,7 +2158,7 @@ async def comment(self,

return bool(msg[0])

async def get_attachments(self, ticket_id: typing.Union[str, int]) -> collections.abc.AsyncIterator[typing.Dict[str, str]]:
async def get_attachments(self, ticket_id: typing.Union[str, int]) -> collections.abc.AsyncIterator:
""" Get attachment list for a given ticket
Example of a return result:
Expand All @@ -2173,19 +2177,20 @@ async def get_attachments(self, ticket_id: typing.Union[str, int]) -> collection
]
:param ticket_id: ID of ticket
:returns: Iterator of attachments belonging to given ticket.
:returns: Iterator of attachments belonging to given ticket. collections.abc.AsyncIterator[typing.Dict[str, str]]
"""
async for item in self.__paged_request(f'ticket/{ticket_id}/attachments',
json_data=[{'field': 'Filename', 'operator': 'IS NOT', 'value': ''}],
params={'fields': 'Filename,ContentType,ContentLength'}):
yield item

async def get_attachments_ids(self, ticket_id: typing.Union[str, int]) -> collections.abc.AsyncIterator[int]:
async def get_attachments_ids(self, ticket_id: typing.Union[str, int]) -> collections.abc.AsyncIterator:
""" Get IDs of attachments for given ticket.
:param ticket_id: ID of ticket
:returns: Iterator of IDs (type int) of attachments belonging to given
ticket.
collections.abc.AsyncIterator[int]
"""
async for item in self.__paged_request(f'ticket/{ticket_id}/attachments',
json_data=[{'field': 'Filename', 'operator': 'IS NOT', 'value': ''}],
Expand Down Expand Up @@ -2513,7 +2518,7 @@ async def get_queue(self, queue_id: typing.Union[str, int]) -> typing.Optional[t

return res

async def get_all_queues(self, include_disabled: bool = False) -> collections.abc.AsyncIterator[typing.Dict[str, typing.Any]]:
async def get_all_queues(self, include_disabled: bool = False) -> collections.abc.AsyncIterator:
""" Return a list of all queues.
Example of a return result:
Expand All @@ -2538,6 +2543,7 @@ async def get_all_queues(self, include_disabled: bool = False) -> collections.ab
:param include_disabled: Set to True to also return disabled queues.
:returns: Iterator of dictionaries containing basic information on all queues.
collections.abc.AsyncIterator[typing.Dict[str, typing.Any]]
:raises UnexpectedMessageFormatError: In case that returned status code is not 200
"""
Expand Down

0 comments on commit 0c50c5f

Please sign in to comment.