Skip to content

Commit 6f631f0

Browse files
committed
Type fixes
1 parent 5551fb6 commit 6f631f0

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

reportportal_client/helpers/common_helpers.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import uuid
2525
from platform import machine, processor, system
2626
from types import MappingProxyType
27-
from typing import Any, Callable, Generic, Iterable, Optional, TypeVar, Union
27+
from typing import Any, Callable, Generic, Iterable, Optional, Sized, TypeVar, Union
2828

2929
from reportportal_client.core.rp_file import RPFile
3030

@@ -260,7 +260,10 @@ def verify_value_length(attributes: Optional[Union[list[dict], dict]]) -> Option
260260

261261
my_attributes = attributes
262262
if isinstance(my_attributes, dict):
263-
my_attributes = dict_to_payload(my_attributes)
263+
converted_attributes = dict_to_payload(my_attributes)
264+
if converted_attributes is None:
265+
return None
266+
my_attributes = converted_attributes
264267

265268
result = []
266269
for pair in my_attributes:
@@ -312,7 +315,7 @@ def root_uri_join(*uri_parts: str) -> str:
312315
return "/" + uri_join(*uri_parts)
313316

314317

315-
def get_function_params(func: Callable, args: tuple, kwargs: dict[str, Any]) -> dict[str, Any]:
318+
def get_function_params(func: Callable, args: tuple, kwargs: dict[str, Any]) -> Optional[dict[str, Any]]:
316319
"""Extract argument names from the function and combine them with values.
317320
318321
:param func: the function to get arg names
@@ -379,7 +382,9 @@ def calculate_file_part_size(file: Optional[RPFile]) -> int:
379382
if file is None:
380383
return 0
381384
size = len(TYPICAL_FILE_PART_HEADER.format(file.name, file.content_type))
382-
size += len(file.content)
385+
content = file.content
386+
if isinstance(content, Sized):
387+
size += len(content)
383388
return size
384389

385390

@@ -435,9 +440,10 @@ def guess_content_type_from_bytes(data: Union[bytes, bytearray, list[int]]) -> s
435440
:param data: bytes or bytearray
436441
:return: content type
437442
"""
438-
my_data = data
439443
if isinstance(data, list):
440-
my_data = bytes(my_data)
444+
my_data: Union[bytes, bytearray] = bytes(data)
445+
else:
446+
my_data = data
441447

442448
if len(my_data) >= BYTES_TO_READ_FOR_DETECTION:
443449
my_data = my_data[:BYTES_TO_READ_FOR_DETECTION]

0 commit comments

Comments
 (0)