fields-metadata 1.4.1__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.
@@ -0,0 +1,43 @@
1
+ """fields-metadata: A Python library for extracting field metadata from dataclasses and Pydantic models."""
2
+
3
+ from fields_metadata.annotations import (
4
+ FinalType,
5
+ HumanReadableId,
6
+ InternationalURNAnnotation,
7
+ Multiline,
8
+ NonCategorical,
9
+ SemanticClassification,
10
+ SuggestedValidation,
11
+ URNAnnotation,
12
+ final_type,
13
+ )
14
+ from fields_metadata.exceptions import (
15
+ FieldMetadataError,
16
+ InvalidTypeUnionError,
17
+ NoneTypeFieldError,
18
+ )
19
+ from fields_metadata.extractor import MetadataExtractor
20
+ from fields_metadata.metadata import FieldMetadata
21
+ from fields_metadata.path import FieldsMetadataMap, FieldsPath
22
+
23
+ __version__ = "1.4.1"
24
+
25
+ __all__ = [
26
+ "MetadataExtractor",
27
+ "FieldMetadata",
28
+ "FieldsPath",
29
+ "FieldsMetadataMap",
30
+ "FinalType",
31
+ "Multiline",
32
+ "HumanReadableId",
33
+ "NonCategorical",
34
+ "SemanticClassification",
35
+ "SuggestedValidation",
36
+ "URNAnnotation",
37
+ "InternationalURNAnnotation",
38
+ "final_type",
39
+ "FieldMetadataError",
40
+ "InvalidTypeUnionError",
41
+ "NoneTypeFieldError",
42
+ "__version__",
43
+ ]
@@ -0,0 +1,119 @@
1
+ """Custom annotation types for field metadata."""
2
+
3
+ from dataclasses import dataclass
4
+ from typing import Any, TypeVar
5
+
6
+ _T = TypeVar("_T")
7
+
8
+
9
+ @dataclass(frozen=True)
10
+ class Multiline:
11
+ """Annotation to mark a string field as multiline text."""
12
+
13
+
14
+ @dataclass(frozen=True)
15
+ class HumanReadableId:
16
+ """Annotation to mark a field as a human-readable identifier."""
17
+
18
+
19
+ @dataclass(frozen=True)
20
+ class SemanticClassification:
21
+ """
22
+ Annotation for semantic classification of a field.
23
+
24
+ :param classification: The semantic classification value
25
+ """
26
+
27
+ classification: str
28
+
29
+
30
+ @dataclass(frozen=True)
31
+ class URNAnnotation:
32
+ """Annotation to mark a field as a URN."""
33
+
34
+
35
+ @dataclass(frozen=True)
36
+ class InternationalURNAnnotation(URNAnnotation):
37
+ """Annotation to mark a field as an international URN."""
38
+
39
+
40
+ @dataclass(frozen=True)
41
+ class NonCategorical:
42
+ """Annotation to mark a field as non-categorical."""
43
+
44
+
45
+ @dataclass(frozen=True)
46
+ class SuggestedValidation:
47
+ """
48
+ Annotation to manually set the suggested_validation metadata.
49
+
50
+ :param validation: The validation type to suggest
51
+ """
52
+
53
+ validation: str
54
+
55
+
56
+ @dataclass(frozen=True)
57
+ class FinalType:
58
+ """
59
+ Annotation to mark a type as final (non-composite).
60
+
61
+ When used with typing.Annotated, prevents the metadata extractor from
62
+ traversing into the type's fields.
63
+
64
+ Example:
65
+ from typing import Annotated
66
+ from fields_metadata.annotations import FinalType
67
+
68
+ # Mark a field's type as final
69
+ value: Annotated[MyCustomType, FinalType()]
70
+ """
71
+
72
+
73
+ _FINAL_TYPE_MARKER = "__fields_metadata_final_type__"
74
+
75
+
76
+ def final_type(cls: type[_T]) -> type[_T]:
77
+ """
78
+ Decorator to mark a class as a final type.
79
+
80
+ Final types are not traversed by the metadata extractor, even if they
81
+ are dataclasses or Pydantic models.
82
+
83
+ :param cls: The class to mark as final
84
+ :return: The same class with final type marker
85
+
86
+ Example:
87
+ from fields_metadata.annotations import final_type
88
+
89
+ @final_type
90
+ @dataclass
91
+ class MyCustomType:
92
+ value: str
93
+ """
94
+ setattr(cls, _FINAL_TYPE_MARKER, True)
95
+ return cls
96
+
97
+
98
+ def is_marked_final_type(cls: Any) -> bool:
99
+ """
100
+ Check if a class has been marked as a final type using the decorator.
101
+
102
+ :param cls: The class to check
103
+ :return: True if the class is marked as final, False otherwise
104
+ """
105
+ return getattr(cls, _FINAL_TYPE_MARKER, False) is True
106
+
107
+
108
+ __all__ = [
109
+ "Multiline",
110
+ "HumanReadableId",
111
+ "SemanticClassification",
112
+ "URNAnnotation",
113
+ "InternationalURNAnnotation",
114
+ "NonCategorical",
115
+ "SuggestedValidation",
116
+ "FinalType",
117
+ "final_type",
118
+ "is_marked_final_type",
119
+ ]
@@ -0,0 +1,20 @@
1
+ """Custom exceptions for fields-metadata library."""
2
+
3
+
4
+ class FieldMetadataError(Exception):
5
+ """Base exception for fields-metadata library."""
6
+
7
+
8
+ class InvalidTypeUnionError(FieldMetadataError):
9
+ """Raised when a field has a union between non-None types."""
10
+
11
+
12
+ class NoneTypeFieldError(FieldMetadataError):
13
+ """Raised when a field has only None as its type."""
14
+
15
+
16
+ __all__ = [
17
+ "FieldMetadataError",
18
+ "InvalidTypeUnionError",
19
+ "NoneTypeFieldError",
20
+ ]