Skip to content

Add FastlyResource Base Class#47

Merged
posborne merged 2 commits into
mainfrom
posborne/fastly-resource-abc
Apr 7, 2026
Merged

Add FastlyResource Base Class#47
posborne merged 2 commits into
mainfrom
posborne/fastly-resource-abc

Conversation

@posborne
Copy link
Copy Markdown
Member

Add FastlyResource base class for common concerns

Much of the API functinoality is wrapping and providing documentation
and some basic translation on top of an underlying (patched) wit
esource. With that wrapping, however, we need to consistently add
context manager and close() support.

This change moves that common functionality to an abstract base class
with generic types so we continue to have strong typing in our
implementations interactions with the "_inner" WIT resource.


Targeting at the ERL base for now to make review easier; if/when that merges I'll change the base to main. I still have mildly mixed feelings about using inheritance here, but it seems worthwhile to avoid having to repro the docs everywhere.

@posborne posborne requested a review from erikrose February 19, 2026 18:58
Copy link
Copy Markdown
Member

@erikrose erikrose left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's a nice win. LGTM!

@@ -0,0 +1,104 @@
"""Internal base class for Fastly resource wrappers
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we call this _resource.py, then we don't have to scream at the read so much about it being internal. :-)

Comment thread fastly_compute/erl.py Outdated
penalty.add("192.168.1.1", ttl=600) # Block for 10 minutes
"""
self._box.add(entry, ttl)
self._inner.add(entry, ttl)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd love to get a noun in there, since we're often referencing it at some level of remove. _wit_resource, _inner_resource, something like that.

Copy link
Copy Markdown
Member Author

@posborne posborne Apr 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updating to _wit_resource

Comment thread fastly_compute/config_store.py Outdated
def __init__(self, store: wit_config_store.Store):
"""Private constructor. Use ConfigStore.open() instead."""
self._store = store
super().__init__(store)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be able to omit this method.

Comment thread fastly_compute/erl.py Outdated
def __init__(self, counter: wit_erl.RateCounter):
"""Private constructor. Use RateCounter.open() instead."""
self._counter = counter
super().__init__(counter)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

…and this one.

posborne added 2 commits April 7, 2026 16:00
Much of the API functinoality is wrapping and providing documentation
and some basic translation on top of an underlying (patched) wit
resource.  With that wrapping, however, we need to consistently add
context manager and close() support.

This change moves that common functionality to an abstract base class
with generic types so we continue to have strong typing in our
implementations interactions with the "_inner" WIT resource.
- Remove unecessary constructor wrapper calls
- Rename _inner to _wit_resource
- Rename module to _resource from resource as private, remove some of
  the internal disclaimers.
@posborne posborne force-pushed the posborne/fastly-resource-abc branch from e231e99 to 572fc68 Compare April 7, 2026 21:59
@posborne posborne changed the base branch from posborne/erl to main April 7, 2026 22:00
@posborne posborne merged commit 0449cc8 into main Apr 7, 2026
3 checks passed
@posborne posborne deleted the posborne/fastly-resource-abc branch April 7, 2026 22:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants