Skip to content

Commit 49824b3

Browse files
committed
fix: Replace magic number 15 with constant _MAX_SAFE_INTEGER_DIGITS
- Added _MAX_SAFE_INTEGER_DIGITS constant to improve code readability - Replaced hardcoded value 15 with the named constant in metadata conversion
1 parent 22b42d9 commit 49824b3

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/a2a/utils/proto_utils.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
r'tasks/([\w-]+)/pushNotificationConfigs/([\w-]+)'
2424
)
2525

26+
# Maximum safe integer digits (JavaScript MAX_SAFE_INTEGER is 2^53 - 1)
27+
_MAX_SAFE_INTEGER_DIGITS = 15
28+
2629

2730
class ToProto:
2831
"""Converts Python types to proto types."""
@@ -531,7 +534,10 @@ def _convert_proto_to_value(cls, value: struct_pb2.Value) -> Any:
531534
return value.number_value
532535
if value.HasField('string_value'):
533536
string_val = value.string_value
534-
if string_val.lstrip('-').isdigit():
537+
if (
538+
string_val.lstrip('-').isdigit()
539+
and len(string_val.lstrip('-')) > _MAX_SAFE_INTEGER_DIGITS
540+
):
535541
return int(string_val)
536542
return string_val
537543
if value.HasField('struct_value'):

0 commit comments

Comments
 (0)