docling-core 2.41.0__py3-none-any.whl → 2.42.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of docling-core might be problematic. Click here for more details.

@@ -1,7 +1,7 @@
1
1
  """Models for the base data types."""
2
2
 
3
3
  from enum import Enum
4
- from typing import List, Tuple
4
+ from typing import Any, List, Tuple
5
5
 
6
6
  from pydantic import BaseModel, FieldSerializationInfo, field_serializer
7
7
 
@@ -21,16 +21,23 @@ class CoordOrigin(str, Enum):
21
21
  BOTTOMLEFT = "BOTTOMLEFT"
22
22
 
23
23
 
24
- _CTX_COORD_PREC = "coord_prec"
24
+ class PydanticSerCtxKey(str, Enum):
25
+ """Pydantic serialization context keys."""
25
26
 
27
+ COORD_PREC = "coord_prec" # key for coordinates precision
28
+ CONFID_PREC = "confid_prec" # key for confidence values precision
26
29
 
27
- def _serialize_precision(
28
- value: float, info: FieldSerializationInfo, ctx_key: str
30
+
31
+ def round_pydantic_float(
32
+ val: float, ctx: Any, precision_ctx_key: PydanticSerCtxKey
29
33
  ) -> float:
30
- precision = info.context.get(ctx_key) if info.context else None
31
- if isinstance(precision, int):
32
- return round(value, precision)
33
- return value
34
+ """Round float, provided the precision is available in the context."""
35
+ precision = (
36
+ ctx.get(precision_ctx_key.value)
37
+ if isinstance(ctx, dict)
38
+ else getattr(ctx, precision_ctx_key.value, None)
39
+ )
40
+ return round(val, precision) if isinstance(precision, int) else val
34
41
 
35
42
 
36
43
  class Size(BaseModel):
@@ -41,7 +48,7 @@ class Size(BaseModel):
41
48
 
42
49
  @field_serializer("width", "height")
43
50
  def _serialize(self, value: float, info: FieldSerializationInfo) -> float:
44
- return _serialize_precision(value, info, _CTX_COORD_PREC)
51
+ return round_pydantic_float(value, info.context, PydanticSerCtxKey.COORD_PREC)
45
52
 
46
53
  def as_tuple(self):
47
54
  """as_tuple."""
@@ -70,7 +77,7 @@ class BoundingBox(BaseModel):
70
77
 
71
78
  @field_serializer("l", "t", "r", "b")
72
79
  def _serialize(self, value: float, info: FieldSerializationInfo) -> float:
73
- return _serialize_precision(value, info, _CTX_COORD_PREC)
80
+ return round_pydantic_float(value, info.context, PydanticSerCtxKey.COORD_PREC)
74
81
 
75
82
  def resize_by_scale(self, x_scale: float, y_scale: float):
76
83
  """resize_by_scale."""