Skip to content

Commit 4d72b70

Browse files
committed
Fix some warnings
1 parent a10d050 commit 4d72b70

7 files changed

Lines changed: 47 additions & 29 deletions

File tree

reportportal_client/__init__.py

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

1414
"""This package is the base package for ReportPortal client."""
1515
import typing
16-
import warnings
1716

1817
import aenum
1918

@@ -101,7 +100,7 @@ def create_client(
101100
return ThreadedRPClient(endpoint, project, api_key=api_key, **kwargs)
102101
if client_type is ClientType.ASYNC_BATCHED:
103102
return BatchedRPClient(endpoint, project, api_key=api_key, **kwargs)
104-
warnings.warn(f"Unknown ReportPortal Client type requested: {client_type}", RuntimeWarning, stacklevel=2)
103+
raise ValueError(f"Unknown ReportPortal Client type requested: {client_type}")
105104

106105

107106
__all__ = [

reportportal_client/_internal/aio/tasks.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -177,20 +177,24 @@ def append(self, value: _T) -> Optional[List[_T]]:
177177
:return: a batch or None
178178
"""
179179
self.__task_list.append(value)
180-
if self.__ready_to_run():
181-
tasks = self.__task_list
182-
self.__task_list = []
183-
return tasks
180+
if not self.__ready_to_run():
181+
return None
182+
183+
tasks = self.__task_list
184+
self.__task_list = []
185+
return tasks
184186

185187
def flush(self) -> Optional[List[_T]]:
186188
"""Immediately return everything what's left in the internal batch.
187189
188190
:return: a batch or None
189191
"""
190-
if len(self.__task_list) > 0:
191-
tasks = self.__task_list
192-
self.__task_list = []
193-
return tasks
192+
if len(self.__task_list) <= 0:
193+
return None
194+
195+
tasks = self.__task_list
196+
self.__task_list = []
197+
return tasks
194198

195199

196200
class BackgroundTaskList(Generic[_T]):
@@ -224,7 +228,9 @@ def flush(self) -> Optional[List[_T]]:
224228
:return: a batch or None
225229
"""
226230
self.__remove_finished()
227-
if len(self.__task_list) > 0:
228-
tasks = self.__task_list
229-
self.__task_list = []
230-
return tasks
231+
if len(self.__task_list) <= 0:
232+
return None
233+
234+
tasks = self.__task_list
235+
self.__task_list = []
236+
return tasks

reportportal_client/_internal/local/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ def current():
2222
"""Return current ReportPortal client."""
2323
if hasattr(__INSTANCES, "current"):
2424
return __INSTANCES.current
25+
return None
2526

2627

2728
def set_current(client):

reportportal_client/_internal/logs/batcher.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def __init__(self, entry_num=MAX_LOG_BATCH_SIZE, payload_limit=MAX_LOG_BATCH_PAY
5050
self._batch = []
5151
self._payload_size = 0
5252

53-
def _append(self, size: int, log_req: T_co) -> Optional[List[T_co]]:
53+
def _append(self, size: int, log_req: RPRequestLog) -> Optional[List[RPRequestLog]]:
5454
with self._lock:
5555
if self._payload_size + size >= self.payload_limit:
5656
if len(self._batch) > 0:
@@ -60,11 +60,13 @@ def _append(self, size: int, log_req: T_co) -> Optional[List[T_co]]:
6060
return batch
6161
self._batch.append(log_req)
6262
self._payload_size += size
63-
if len(self._batch) >= self.entry_num:
64-
batch = self._batch
65-
self._batch = []
66-
self._payload_size = 0
67-
return batch
63+
if len(self._batch) < self.entry_num:
64+
return None
65+
66+
batch = self._batch
67+
self._batch = []
68+
self._payload_size = 0
69+
return batch
6870

6971
def append(self, log_req: RPRequestLog) -> Optional[List[RPRequestLog]]:
7072
"""Add a log request object to internal batch and return the batch if it's full.
@@ -87,12 +89,15 @@ def flush(self) -> Optional[List[T_co]]:
8789
8890
:return: a batch or None
8991
"""
92+
if len(self._batch) <= 0:
93+
return None
9094
with self._lock:
91-
if len(self._batch) > 0:
92-
batch = self._batch
93-
self._batch = []
94-
self._payload_size = 0
95-
return batch
95+
if len(self._batch) <= 0:
96+
return None
97+
batch = self._batch
98+
self._batch = []
99+
self._payload_size = 0
100+
return batch
96101

97102
def __getstate__(self) -> Dict[str, Any]:
98103
"""Control object pickling and return object fields as Dictionary.

reportportal_client/_internal/services/client_id.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ def _read_client_id():
5757
config = __read_config()
5858
if config.has_option(__NoSectionConfigParser.DEFAULT_SECTION, CLIENT_ID_PROPERTY):
5959
return config.get(__NoSectionConfigParser.DEFAULT_SECTION, CLIENT_ID_PROPERTY)
60+
return None
6061

6162

6263
def _store_client_id(client_id):

reportportal_client/_internal/services/statistics.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@ def _get_payload(event_name: str, agent_name: Optional[str], agent_version: Opti
7373
return {"client_id": get_client_id(), "events": [{"name": event_name, "params": request_params}]}
7474

7575

76-
def send_event(event_name: str, agent_name: Optional[str], agent_version: Optional[str]) -> requests.Response:
76+
def send_event(
77+
event_name: str, agent_name: Optional[str], agent_version: Optional[str]
78+
) -> Optional[requests.Response]:
7779
"""Send an event to statistics service.
7880
7981
Use client and agent versions with their names.
@@ -120,7 +122,7 @@ async def async_send_event(
120122
)
121123
except aiohttp.ClientError as exc:
122124
logger.debug("Failed to send data to Statistics service: connection error", exc)
123-
return
125+
return None
124126
if not result.ok:
125127
logger.debug(f"Failed to send data to Statistics service: {result.reason}")
126128
return result

reportportal_client/helpers/common_helpers.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
class LifoQueue(Generic[_T]):
6969
"""Primitive thread-safe Last-in-first-out queue implementation."""
7070

71-
_lock: threading.Lock()
71+
_lock: threading.Lock
7272
__items: List[_T]
7373

7474
def __init__(self):
@@ -98,9 +98,13 @@ def last(self) -> _T:
9898
9999
:return: The last element in the queue.
100100
"""
101+
if len(self.__items) <= 0:
102+
return None
103+
101104
with self._lock:
102105
if len(self.__items) > 0:
103106
return self.__items[-1]
107+
return None
104108

105109
def qsize(self):
106110
"""Return the queue size."""
@@ -149,7 +153,7 @@ def dict_to_payload(dictionary: Optional[dict]) -> Optional[List[dict]]:
149153
hidden = my_dictionary.pop("system", None)
150154
result = []
151155
for key, value in sorted(my_dictionary.items()):
152-
attribute = {"key": str(key), "value": str(value)}
156+
attribute: Dict[str, Any] = {"key": str(key), "value": str(value)}
153157
if hidden is not None:
154158
attribute["system"] = hidden
155159
result.append(attribute)

0 commit comments

Comments
 (0)