Skip to content

Commit 88c18b9

Browse files
jsonbaileyclaude
andcommitted
refactor: Use typing.Self for disabled() return type, remove redundant overrides
The base AIConfigDefault.disabled() already uses cls(), so subclass overrides were unnecessary. Use Self return type annotation for correct narrowing and remove the three identical overrides from AICompletionConfigDefault, AIAgentConfigDefault, AIJudgeConfigDefault. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent d721142 commit 88c18b9

1 file changed

Lines changed: 8 additions & 13 deletions

File tree

packages/sdk/server-ai/src/ldai/models.py

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
1+
from __future__ import annotations
2+
13
import warnings
24
from dataclasses import dataclass, field
35
from typing import Any, Callable, Dict, List, Literal, Optional, Union
46

7+
try:
8+
from typing import Self
9+
except ImportError:
10+
from typing_extensions import Self
11+
512

613
@dataclass
714
class LDMessage:
@@ -151,7 +158,7 @@ class AIConfigDefault:
151158
provider: Optional[ProviderConfig] = None
152159

153160
@classmethod
154-
def disabled(cls) -> 'AIConfigDefault':
161+
def disabled(cls) -> Self:
155162
return cls(enabled=False)
156163

157164
def _base_to_dict(self) -> Dict[str, Any]:
@@ -207,10 +214,6 @@ class AICompletionConfigDefault(AIConfigDefault):
207214
messages: Optional[List[LDMessage]] = None
208215
judge_configuration: Optional[JudgeConfiguration] = None
209216

210-
@classmethod
211-
def disabled(cls) -> 'AICompletionConfigDefault':
212-
return cls(enabled=False)
213-
214217
def to_dict(self) -> dict:
215218
"""
216219
Render the given default values as an AICompletionConfigDefault-compatible dictionary object.
@@ -253,10 +256,6 @@ class AIAgentConfigDefault(AIConfigDefault):
253256
instructions: Optional[str] = None
254257
judge_configuration: Optional[JudgeConfiguration] = None
255258

256-
@classmethod
257-
def disabled(cls) -> 'AIAgentConfigDefault':
258-
return cls(enabled=False)
259-
260259
def to_dict(self) -> Dict[str, Any]:
261260
"""
262261
Render the given agent config default as a dictionary object.
@@ -303,10 +302,6 @@ class AIJudgeConfigDefault(AIConfigDefault):
303302
evaluation_metric_keys: Optional[List[str]] = None
304303
evaluation_metric_key: Optional[str] = None
305304

306-
@classmethod
307-
def disabled(cls) -> 'AIJudgeConfigDefault':
308-
return cls(enabled=False)
309-
310305
def to_dict(self) -> dict:
311306
"""
312307
Render the given judge config default as a dictionary object.

0 commit comments

Comments
 (0)