Coverage for src/python/ensembl/vep/buffer/base.py: 100%
14 statements
« prev ^ index » next coverage.py v7.17.2, created at 2026-11-18 14:41 +0000
« prev ^ index » next coverage.py v7.17.2, created at 2026-11-18 14:41 +0000
1# See the NOTICE file distributed with this work for additional information
2# regarding copyright ownership.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14"""The buffer contract.
16A buffer holds one batch of input objects. It is handed the objects to draw from, rather than
17holding a source of its own, so a buffer stays picklable and reading stays with the input source.
18"""
20from __future__ import annotations
22from collections.abc import Iterator
23from typing import Protocol, TypeVar, runtime_checkable
25__all__ = ["Buffer"]
27ItemT = TypeVar("ItemT")
28"""What item type a buffer holds."""
31@runtime_checkable
32class Buffer(Protocol[ItemT]):
33 """Refillable batch of input items."""
35 @property
36 def objects(self) -> tuple[ItemT, ...]:
37 """Return the items in the current batch, in input order."""
38 raise NotImplementedError
40 @property
41 def is_empty(self) -> bool:
42 """Return whether the input the batch is drawn from is spent."""
43 raise NotImplementedError
45 def next(self, items: Iterator[ItemT]) -> None:
46 """Reset the batch and refill it from ``items``."""
47 raise NotImplementedError
49 def clear(self) -> None:
50 """Drop whatever was indexed for the current batch."""
51 raise NotImplementedError