chore(sdk): tighten get_class docstring and unknown-provider test

- Reword get_class docstring: it may populate the _ep_providers cache,
  rather than claiming "no global state"
- Assert ImportError specifically in the unknown-provider test to enforce
  the public API contract
- Drop the unused provider_class_name left over after get_class delegation
This commit is contained in:
StylusFrost committed 2026-06-01 20:28:19 +02:00
1 parent ece6af5dd3
commit a111ae763c
2 files changed
+8 -15

No files matched your search

+4 -10
View File
@@ -302,13 +302,6 @@ class Provider(ABC):
f"it under a different name."
)
# Kept for downstream forks that may extend the dispatch below
# with their own custom built-in branches and reference this name.
# The upstream chain dispatches by `arguments.provider` directly.
provider_class_name = (
f"{arguments.provider.capitalize()}Provider" # noqa: F841
)
fixer_config = load_and_validate_config_file(
arguments.provider, arguments.fixer_config
)
@@ -689,9 +682,10 @@ class Provider(ABC):
def get_class(provider: str) -> type:
"""Resolve the provider class for a name (built-in or entry-point).
Side-effect-free: no ``sys.exit``, no global state. Collision warnings
are emitted by ``init_global_provider``, not here. The caller handles
errors (CLI exits; the API can return HTTP 400).
Does not call ``sys.exit`` and does not initialize the global
provider (it may populate the ``_ep_providers`` memoization cache).
Collision warnings are emitted by ``init_global_provider``, not here.
The caller handles errors (CLI exits; the API can return HTTP 400).
Args:
provider: Provider name, e.g. ``"aws"`` or an external plug-in.
+4 -5
View File
@@ -2031,12 +2031,11 @@ class TestGetClass:
mock_is_builtin.return_value = False
mock_ep.return_value = []
with pytest.raises((ImportError, Exception)) as exc_info:
Provider.get_class("totally_unknown_xyz_provider")
# Must NOT be a SystemExit — that belongs in init_global_provider's
# Assert ImportError specifically to enforce the public API contract
# (not a broad Exception). SystemExit belongs in init_global_provider's
# wrapper, not in the pure resolver.
assert not isinstance(exc_info.value, SystemExit)
with pytest.raises(ImportError):
Provider.get_class("totally_unknown_xyz_provider")
# -----------------------------------------------------------------------
# T4: get_class is PURE for built-ins — no collision warning, no EP call