Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert backends from Protocol classes to sets of Callables #132

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

pjhartzell
Copy link

@pjhartzell pjhartzell commented Jan 27, 2025

This PR replaces the backend Protocol classes with Callable type aliases. The Product model class and the RootRouter router class constructors now accept functions matching the newly defined Callable type aliases rather than the backend Protocol classes. This will enable (not in this PR) making these Callable constructor arguments optional, which will then allow product opportunity searching or product ordering to be disabled or enabled based on the presence/non-presence of constructor arguments. Similarly, this will also open the door to optional asynchronous (stateful) opportunity searching.

A few notable changes to the test suite:

  • The backends module has been removed from the tests directory. Its content was never actually being used and was almost entirely duplicative of the code that is being used.
  • The in-memory storage that was attached to the MockProductBackend class is replaced with a FastAPI lifespan for storing state. This was necessary since backends are no longer classes that arbitrary attributes can be attached to.

Related Issue(s):

Proposed Changes:

  1. Replace the backend Protocol classes with Callable type aliases.

PR Checklist:

  • I have added my changes to the CHANGELOG or a CHANGELOG entry is not required.

This change is in preparation for making product opportunity
searching and ordering optional and for introducing optional
asynchronous opportunity searching (which will require state).
A few notable changes to the test suite:
  - The `backends` module has been removed from the `tests` directory.
    Its contents were never actually being used. The contents in
    `conftest` took precedence.
  - The in-memory storage that was attached to the MockProductBackend
    class is replaced with a FastAPI lifespan for storing state.
@philvarner
Copy link
Contributor

Looks good, only a couple of doc fixes suggested.

@pjhartzell pjhartzell marked this pull request as ready for review January 27, 2025 19:10
tests/conftest.py Outdated Show resolved Hide resolved
tests/conftest.py Outdated Show resolved Hide resolved
tests/conftest.py Outdated Show resolved Hide resolved
@pjhartzell pjhartzell force-pushed the pjh/convert-backend-protocols-to-callables branch from cc170f5 to 7a97081 Compare January 27, 2025 23:41
@pjhartzell pjhartzell force-pushed the pjh/convert-backend-protocols-to-callables branch from 7a97081 to a9a7502 Compare January 27, 2025 23:52
@pjhartzell pjhartzell force-pushed the pjh/convert-backend-protocols-to-callables branch from 3b7de57 to 24f753a Compare January 28, 2025 00:03
@pjhartzell pjhartzell force-pushed the pjh/convert-backend-protocols-to-callables branch from 24f753a to b34f8d9 Compare January 28, 2025 00:07
@pjhartzell pjhartzell force-pushed the pjh/convert-backend-protocols-to-callables branch from b34f8d9 to 48e077b Compare January 28, 2025 00:09
@pjhartzell pjhartzell force-pushed the pjh/convert-backend-protocols-to-callables branch from 48e077b to 833b871 Compare January 28, 2025 01:29
@pjhartzell pjhartzell force-pushed the pjh/convert-backend-protocols-to-callables branch from 833b871 to 7d03976 Compare January 28, 2025 01:33
@pjhartzell pjhartzell force-pushed the pjh/convert-backend-protocols-to-callables branch from 61d6257 to 92bfb3f Compare January 28, 2025 02:25
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.

3 participants