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

v2: ValueChecker needs a default value for _last_value #1156

Open
rosesyrett opened this issue Sep 5, 2023 · 0 comments
Open

v2: ValueChecker needs a default value for _last_value #1156

rosesyrett opened this issue Sep 5, 2023 · 0 comments

Comments

@rosesyrett
Copy link
Contributor

Recently, at diamond we've been coming across an error that occasionally crops up and originates in the _ValueChecker:

class _ValueChecker(Generic[T]):
    def __init__(self, matcher: Callable[[T], bool], matcher_name: str):
        self._last_value: Optional[T]
        self._matcher = matcher
        self._matcher_name = matcher_name

    ...

    async def wait_for_value(self, signal: SignalR[T], timeout: float):
        try:
            await asyncio.wait_for(self._wait_for_value(signal), timeout)
        except asyncio.TimeoutError as e:
            raise TimeoutError(
                f"{signal.name} didn't match {self._matcher_name} in {timeout}s, "
                f"last value {self._last_value!r}"
            ) from e

we found the TimeoutError inconsistently raised AttributeError complaining that _ValueChecker doesn't have the attribute ._last_value.

To fix, the __init__ should look like:

class _ValueChecker(Generic[T]):
    def __init__(self, matcher: Callable[[T], bool], matcher_name: str):
        self._last_value: Optional[T] = None
        self._matcher = matcher
        self._matcher_name = matcher_name
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

No branches or pull requests

1 participant