Skip to content

Commit d9d530b

Browse files
committed
Type-check and EncodingWarning clean: the backend-settings code narrows an optional access policy; the test writes its login files as UTF-8
Signed-off-by: Maxime Rivest <mrive052@gmail.com>
1 parent 18ee08e commit d9d530b

5 files changed

Lines changed: 7 additions & 6 deletions

File tree

‎lm15/providers/anthropic.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ def normalize_error(self, status: int, body: str) -> ProviderError:
405405
msg = err.get("message", "") if isinstance(err, dict) else str(err)
406406
err_type = str(err.get("type") or err.get("code") or "") if isinstance(err, dict) else ""
407407
request_id = str(data.get("request_id") or "") if isinstance(data, dict) else ""
408-
if self.access.backend == "claude-code":
408+
if self.access is not None and self.access.backend == "claude-code":
409409
from ..access import claude_code_version_guidance
410410

411411
msg = claude_code_version_guidance(msg)

‎lm15/providers/claude_code.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def __init__(
5757
settings=settings,
5858
adaptations=adaptations,
5959
)
60-
self.claude_code_version = self.access.backend_options["client_version"]
60+
self.claude_code_version = (self.access or CLAUDE_CODE).backend_options["client_version"]
6161

6262
@classmethod
6363
def from_claude_code(

‎lm15/providers/openai_codex.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def __init__(
6565
settings=settings,
6666
adaptations=adaptations,
6767
)
68-
self.client_version = self.access.backend_options["client_version"]
68+
self.client_version = (self.access or OPENAI_CODEX).backend_options["client_version"]
6969

7070
@classmethod
7171
def from_codex_cli(

‎lm15/router.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
from .providers import Credential
8686
from .registry import PROVIDERS, Compat, ProviderDefinition, canonical_provider as _canonical_provider
8787
from .adaptation import AdaptationPolicy, check_policy
88+
from .features import AccessPolicy
8889
from .transports import Timeouts
8990
from .types import Request, Response, StreamEvent
9091

@@ -943,7 +944,7 @@ def _backend_settings(config: RouterConfig, provider: str, cls: type,
943944
would read it."""
944945
from .access import resolve_backend_settings
945946

946-
policy = definition.access if definition is not None else cls.manifest
947+
policy: AccessPolicy = definition.access if definition is not None else getattr(cls, "manifest")
947948
given = _settings_entry(config, provider)
948949
if not given and not policy.backend_settings:
949950
return None

‎tests/test_backend_settings.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ def _hermetic_logins(tmp_path, monkeypatch: pytest.MonkeyPatch) -> None:
4040

4141
claude = tmp_path / "claude.json"
4242
claude.write_text(json.dumps({"claudeAiOauth": {"accessToken": "tok", "refreshToken": "r",
43-
"expiresAt": int(time.time() * 1000) + 3_600_000}}))
43+
"expiresAt": int(time.time() * 1000) + 3_600_000}}), encoding="utf-8")
4444
codex = tmp_path / "codex.json"
45-
codex.write_text(json.dumps({"tokens": {"access_token": "tok", "refresh_token": "r", "account_id": "acct"}}))
45+
codex.write_text(json.dumps({"tokens": {"access_token": "tok", "refresh_token": "r", "account_id": "acct"}}), encoding="utf-8")
4646
monkeypatch.setattr(lm15.auth, "CLAUDE_CODE_CREDENTIALS_PATH", claude)
4747
monkeypatch.setattr(lm15.auth, "CODEX_CLI_AUTH_PATH", codex)
4848
monkeypatch.setenv("LM15_LOCK_DIR", str(tmp_path / "locks"))

0 commit comments

Comments
 (0)