erdantic.plugins.dataclasses¶
get_fields_from_dataclass
¶
Given a dataclass, return a list of FieldInfo instances for each field in the class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model |
DataclassType
|
The dataclass to get fields from. |
required |
Returns:
Type | Description |
---|---|
List[FieldInfo]
|
List of FieldInfo instances for each field in the class |
Source code in erdantic/plugins/dataclasses.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
|
is_dataclass_class
¶
is_dataclass_class(obj: Any) -> TypeGuard[DataclassType]
Predicate function to determine if an object is a dataclass (not an instance).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj |
Any
|
The object to check. |
required |
Returns:
Type | Description |
---|---|
bool
|
True if the object is a dataclass, False otherwise. |
Source code in erdantic/plugins/dataclasses.py
28 29 30 31 32 33 34 35 36 37 |
|
resolve_types_on_dataclass
¶
resolve_types_on_dataclass(
cls: DataclassType,
globalns=None,
localns=None,
include_extras=True,
) -> DataclassType
Resolve forward references in type annotations on a dataclass. This will modify the fields metadata on the class to replace forward references with the actual types.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cls |
DataclassType
|
The dataclass to resolve forward references on. |
required |
globalns |
Dict[str, Any] | None
|
A global namespace to evaluate forward references against. Defaults to None. |
None
|
localns |
Dict[str, Any] | None
|
A local namespace to evaluate forward references against. Defaults to None. |
None
|
include_extras |
bool
|
Whether to keep extra metadata from |
True
|
Source code in erdantic/plugins/dataclasses.py
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
|