Skip to content

Commit 3c403f0

Browse files
committed
A try to fix imports
1 parent f6bcfd1 commit 3c403f0

File tree

5 files changed

+24
-22
lines changed

5 files changed

+24
-22
lines changed

reportportal_client/aio/__init__.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
# limitations under the License
1313

1414
"""Common package for Asynchronous I/O clients and utilities."""
15+
import asyncio
16+
from typing import Coroutine, Optional, TypeVar, Union
1517

1618
from reportportal_client.aio.client import (
1719
DEFAULT_SHUTDOWN_TIMEOUT,
@@ -24,7 +26,25 @@
2426
)
2527
from reportportal_client.aio.tasks import BlockingOperationError, EmptyTask, Task
2628

29+
_T = TypeVar("_T")
30+
31+
32+
async def await_if_necessary(obj: Union[_T, Task[_T], Coroutine[_T, None, None]]) -> Optional[_T]:
33+
"""Await Coroutine, Feature or coroutine Function if given argument is one of them, or return immediately.
34+
35+
:param obj: value, Coroutine, Feature or coroutine Function
36+
:return: result which was returned by Coroutine, Feature or coroutine Function
37+
"""
38+
if obj:
39+
if asyncio.isfuture(obj) or asyncio.iscoroutine(obj):
40+
return await obj
41+
elif asyncio.iscoroutinefunction(obj):
42+
return await obj()
43+
return obj
44+
45+
2746
__all__ = [
47+
"await_if_necessary",
2848
"Task",
2949
"EmptyTask",
3050
"BlockingOperationError",

reportportal_client/aio/client.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
# noinspection PyProtectedMember
5757
from reportportal_client._internal.static.abstract import AbstractBaseClass, abstractmethod
5858
from reportportal_client._internal.static.defines import DEFAULT_LOG_LEVEL
59-
from reportportal_client.aio import EmptyTask
59+
from reportportal_client.aio import EmptyTask, await_if_necessary
6060

6161
# noinspection PyProtectedMember
6262
from reportportal_client.aio.tasks import Task
@@ -81,7 +81,6 @@
8181
LAUNCH_NAME_LENGTH_LIMIT,
8282
LifoQueue,
8383
agent_name_version,
84-
await_if_necessary,
8584
root_uri_join,
8685
uri_join,
8786
)

reportportal_client/core/rp_requests.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,11 @@
3737

3838
# noinspection PyProtectedMember
3939
from reportportal_client._internal.static.defines import DEFAULT_LOG_LEVEL, DEFAULT_PRIORITY, LOW_PRIORITY, Priority
40+
from reportportal_client.aio import await_if_necessary
4041
from reportportal_client.core.rp_file import RPFile
4142
from reportportal_client.core.rp_issues import Issue
4243
from reportportal_client.core.rp_responses import AsyncRPResponse, RPResponse
43-
from reportportal_client.helpers import await_if_necessary, dict_to_payload
44+
from reportportal_client.helpers import dict_to_payload
4445
from reportportal_client.helpers.common_helpers import clean_binary_characters, verify_value_length
4546

4647
try:

reportportal_client/helpers/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
TYPICAL_MULTIPART_FOOTER_LENGTH,
1515
LifoQueue,
1616
agent_name_version,
17-
await_if_necessary,
1817
calculate_file_part_size,
1918
calculate_json_part_size,
2019
caseless_equal,
@@ -53,7 +52,6 @@
5352
"TYPICAL_FILE_PART_HEADER",
5453
"LifoQueue",
5554
"agent_name_version",
56-
"await_if_necessary",
5755
"calculate_file_part_size",
5856
"calculate_json_part_size",
5957
"caseless_equal",

reportportal_client/helpers/common_helpers.py

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
"""This module contains common functions-helpers of the client and agents."""
1515

16-
import asyncio
1716
import fnmatch
1817
import inspect
1918
import re
@@ -23,9 +22,8 @@
2322
from datetime import datetime, timezone
2423
from platform import machine, processor, system
2524
from types import MappingProxyType
26-
from typing import Any, Callable, Coroutine, Generic, Iterable, Optional, Sized, TypeVar, Union
25+
from typing import Any, Callable, Generic, Iterable, Optional, Sized, TypeVar, Union
2726

28-
from reportportal_client.aio import Task
2927
from reportportal_client.core.rp_file import RPFile
3028

3129
try:
@@ -402,20 +400,6 @@ def agent_name_version(attributes: Optional[Union[list, dict]] = None) -> tuple[
402400
return agent_name, agent_version
403401

404402

405-
async def await_if_necessary(obj: Union[_T, Task[_T], Coroutine[_T, None, None]]) -> Optional[_T]:
406-
"""Await Coroutine, Feature or coroutine Function if given argument is one of them, or return immediately.
407-
408-
:param obj: value, Coroutine, Feature or coroutine Function
409-
:return: result which was returned by Coroutine, Feature or coroutine Function
410-
"""
411-
if obj:
412-
if asyncio.isfuture(obj) or asyncio.iscoroutine(obj):
413-
return await obj
414-
elif asyncio.iscoroutinefunction(obj):
415-
return await obj()
416-
return obj
417-
418-
419403
def is_binary(iterable: Union[bytes, bytearray, str]) -> bool:
420404
"""Check if given iterable is binary.
421405

0 commit comments

Comments
 (0)