Skip to content

Commit 572fc68

Browse files
committed
Address review feedback on resource base class
- Remove unecessary constructor wrapper calls - Rename _inner to _wit_resource - Rename module to _resource from resource as private, remove some of the internal disclaimers.
1 parent 3bcdc2a commit 572fc68

3 files changed

Lines changed: 9 additions & 22 deletions

File tree

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ class WitResource(Protocol):
1919
2020
This protocol defines the context manager interface that all WIT resources
2121
must implement for resource lifecycle management.
22-
23-
**Internal use only** - do not use directly.
2422
"""
2523

2624
def __enter__(self) -> Self:
@@ -44,19 +42,16 @@ class FastlyResource[T: WitResource]:
4442
resource lifecycle management for all Fastly resource types that wrap
4543
WIT bindings (e.g., ConfigStore, RateCounter, PenaltyBox, LogEndpoint).
4644
47-
**Internal use only** - do not instantiate or subclass directly. Use the
48-
public resource classes instead (ConfigStore, RateCounter, etc.).
49-
5045
The type parameter T represents the underlying WIT binding resource type
5146
and must satisfy the WitResource protocol (context manager support).
5247
"""
5348

54-
def __init__(self, inner: T):
49+
def __init__(self, wit_resource: T):
5550
"""Initialize the resource wrapper with an inner WIT binding.
5651
57-
:param inner: The underlying WIT binding resource to wrap
52+
:param wit_resource: The underlying WIT binding resource to wrap
5853
"""
59-
self._inner = inner
54+
self._wit_resource = wit_resource
6055

6156
def close(self) -> None:
6257
"""Explicitly close the resource, releasing its resources.
@@ -68,7 +63,7 @@ def close(self) -> None:
6863
Note: Attempting to use the resource after it is closed will result
6964
in a trap.
7065
"""
71-
self._inner.__exit__(None, None, None)
66+
self._wit_resource.__exit__(None, None, None)
7267

7368
def __enter__(self) -> Self:
7469
"""Context manager entry.
@@ -101,4 +96,4 @@ def __exit__(
10196
:param exc_val: Exception value if an exception occurred, None otherwise
10297
:param exc_tb: Exception traceback if an exception occurred, None otherwise
10398
"""
104-
self._inner.__exit__(exc_type, exc_val, exc_tb)
99+
self._wit_resource.__exit__(exc_type, exc_val, exc_tb)

fastly_compute/config_store.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
from wit_world.imports import config_store as wit_config_store
1717

18-
from .resource import FastlyResource
18+
from ._resource import FastlyResource
1919

2020
# The maximum value for a u32, used to signal that we don't want to cap
2121
# the length of values returned by the host. In practice, this limit
@@ -35,10 +35,6 @@ class ConfigStore(FastlyResource[wit_config_store.Store]):
3535
api_url = config.get("api_url", "https://api.example.com")
3636
"""
3737

38-
def __init__(self, store: wit_config_store.Store):
39-
"""Private constructor. Use ConfigStore.open() instead."""
40-
super().__init__(store)
41-
4238
@classmethod
4339
def open(cls, name: str) -> Self:
4440
"""Open a config store by name.
@@ -69,7 +65,7 @@ def get(self, key: str, default: str | None = None) -> str | None:
6965
config = ConfigStore.open("app-config")
7066
api_url = config.get("api_url", "https://api.example.com")
7167
"""
72-
result = self._inner.get(key, _MAX_U32)
68+
result = self._wit_resource.get(key, _MAX_U32)
7369
if result is None:
7470
result = default
7571

fastly_compute/log.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
from wit_world.imports import log as wit_log
3030

31-
from .resource import FastlyResource
31+
from ._resource import FastlyResource
3232

3333

3434
class LogEndpoint(FastlyResource[wit_log.Endpoint]):
@@ -44,10 +44,6 @@ class LogEndpoint(FastlyResource[wit_log.Endpoint]):
4444
endpoint.write(b"Binary log data")
4545
"""
4646

47-
def __init__(self, endpoint: wit_log.Endpoint):
48-
"""Private constructor. Use LogEndpoint.open() instead."""
49-
super().__init__(endpoint)
50-
5147
@classmethod
5248
def open(cls, name: str) -> Self:
5349
r"""Open a logging endpoint by name.
@@ -90,7 +86,7 @@ def write(self, msg: bytes | str) -> None:
9086
"""
9187
if isinstance(msg, str):
9288
msg = msg.encode("utf-8")
93-
self._inner.write(msg)
89+
self._wit_resource.write(msg)
9490

9591

9692
class FastlyLogHandler(logging.Handler):

0 commit comments

Comments
 (0)