Skip to content

Commit 70e838d

Browse files
committed
Fix typing
1 parent 419334b commit 70e838d

File tree

1 file changed

+6
-4
lines changed
  • opentelemetry-api/src/opentelemetry/attributes

1 file changed

+6
-4
lines changed

opentelemetry-api/src/opentelemetry/attributes/__init__.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,15 +120,15 @@ def _clean_attribute(
120120

121121
def _clean_extended_attribute_value(
122122
value: types.AttributeValue, max_len: Optional[int]
123-
) -> Optional[Union[types.AttributeValue, Tuple[Union[str, int, float], ...]]]:
123+
) -> types.AnyValue:
124124
# for primitive types just return the value and eventually shorten the string length
125125
if value is None or isinstance(value, _VALID_ATTR_VALUE_TYPES):
126126
if max_len is not None and isinstance(value, str):
127127
value = value[:max_len]
128128
return value
129129

130130
if isinstance(value, Mapping):
131-
cleaned_dict = {}
131+
cleaned_dict: dict[str, types.AnyValue] = {}
132132
for key, element in value.items():
133133
# skip invalid keys
134134
if not (key and isinstance(key, str)):
@@ -157,7 +157,9 @@ def _clean_extended_attribute_value(
157157

158158
element_type = type(element)
159159
if element_type not in _VALID_ATTR_VALUE_TYPES:
160-
return _clean_extended_attribute(element, max_len=max_len)
160+
return _clean_extended_attribute_value(
161+
element, max_len=max_len
162+
)
161163

162164
# The type of the sequence must be homogeneous. The first non-None
163165
# element determines the type of the sequence
@@ -187,7 +189,7 @@ def _clean_extended_attribute_value(
187189

188190
def _clean_extended_attribute(
189191
key: str, value: types.AttributeValue, max_len: Optional[int]
190-
) -> Optional[Union[types.AttributeValue, Tuple[Union[str, int, float], ...]]]:
192+
) -> types.AnyValue:
191193
"""Checks if attribute value is valid and cleans it if required.
192194
193195
The function returns the cleaned value or None if the value is not valid.

0 commit comments

Comments
 (0)