|
21 | 21 | from dataclasses import dataclass, field |
22 | 22 |
|
23 | 23 | from metaclass_registry import AutoRegisterMeta |
24 | | -from .annotation_types import optional_member_type |
| 24 | +from .annotation_types import optional_member_type, resolved_class_annotations |
25 | 25 | from .docstring_annotations import infer_parameter_annotation |
26 | 26 |
|
27 | 27 | # ============================================================================= |
@@ -1042,48 +1042,30 @@ def _analyze_dataclass(dataclass_type: type) -> Dict[str, ParameterInfo]: |
1042 | 1042 |
|
1043 | 1043 | logger.debug(f"❌ CACHE MISS for {dataclass_type.__name__} (id={id(dataclass_type)}), cache has {len(SignatureAnalyzer._dataclass_analysis_cache)} entries") |
1044 | 1044 |
|
1045 | | - try: |
1046 | | - # Try to get type hints, fall back to __annotations__ if resolution fails |
1047 | | - try: |
1048 | | - type_hints = get_type_hints(dataclass_type, include_extras=True) |
1049 | | - except Exception: |
1050 | | - type_hints = inspect.get_annotations(dataclass_type, eval_str=False) |
1051 | | - |
1052 | | - parameters = {} |
1053 | | - |
1054 | | - for field in dataclasses.fields(dataclass_type): |
1055 | | - # Skip dunder fields (internal/reserved fields) |
1056 | | - if field.name.startswith(CONSTANTS.DUNDER_PREFIX) and field.name.endswith(CONSTANTS.DUNDER_SUFFIX): |
1057 | | - continue |
1058 | | - |
1059 | | - param_type = type_hints.get(field.name, str) |
1060 | | - |
1061 | | - # Get default value |
1062 | | - if field.default != dataclasses.MISSING: |
1063 | | - default_value = field.default |
1064 | | - is_required = False |
1065 | | - elif field.default_factory != dataclasses.MISSING: |
1066 | | - default_value = field.default_factory() |
1067 | | - is_required = False |
1068 | | - else: |
1069 | | - default_value = None |
1070 | | - is_required = True |
1071 | | - |
1072 | | - parameters[field.name] = ParameterInfo( |
1073 | | - name=field.name, |
1074 | | - param_type=param_type, |
1075 | | - default_value=default_value, |
1076 | | - is_required=is_required, |
1077 | | - description_owner=dataclass_type, |
1078 | | - ) |
1079 | | - |
1080 | | - # PERFORMANCE: Cache the result to avoid re-parsing |
1081 | | - SignatureAnalyzer._dataclass_analysis_cache[cache_key] = parameters |
1082 | | - return parameters |
1083 | | - |
1084 | | - except Exception: |
1085 | | - # Return empty dict on error (don't cache errors) |
1086 | | - return {} |
| 1045 | + type_hints = resolved_class_annotations(dataclass_type) |
| 1046 | + parameters = {} |
| 1047 | + for field in dataclasses.fields(dataclass_type): |
| 1048 | + if field.name.startswith(CONSTANTS.DUNDER_PREFIX) and field.name.endswith(CONSTANTS.DUNDER_SUFFIX): |
| 1049 | + continue |
| 1050 | + param_type = type_hints[field.name] |
| 1051 | + if field.default is not dataclasses.MISSING: |
| 1052 | + default_value = field.default |
| 1053 | + is_required = False |
| 1054 | + elif field.default_factory is not dataclasses.MISSING: |
| 1055 | + default_value = field.default_factory() |
| 1056 | + is_required = False |
| 1057 | + else: |
| 1058 | + default_value = None |
| 1059 | + is_required = True |
| 1060 | + parameters[field.name] = ParameterInfo( |
| 1061 | + name=field.name, |
| 1062 | + param_type=param_type, |
| 1063 | + default_value=default_value, |
| 1064 | + is_required=is_required, |
| 1065 | + description_owner=dataclass_type, |
| 1066 | + ) |
| 1067 | + SignatureAnalyzer._dataclass_analysis_cache[cache_key] = parameters |
| 1068 | + return parameters |
1087 | 1069 |
|
1088 | 1070 | @staticmethod |
1089 | 1071 | def _materialize_dataclass_descriptions(dataclass_type: type, requested: ParameterInfo) -> None: |
|
0 commit comments