Skip to content

Commit ba6b8cd

Browse files
Culaiiclaude
andcommitted
[atheris] Add FuzzedDataProvider and re-export the public API
Add `atheris/native.pyi` (where `FuzzedDataProvider`, `Setup`, `Fuzz`, `Mutate` and `ALL_REMAINING` live at runtime) and re-export the public names from `atheris/__init__.pyi`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent e4a2f22 commit ba6b8cd

3 files changed

Lines changed: 54 additions & 8 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# The metaclass of FuzzedDataProvider is pybind11_builtins.pybind11_type, which is
2+
# not importable from a stub, and pybind11 is not a runtime dependency of atheris.
3+
atheris.native.FuzzedDataProvider

‎stubs/atheris/atheris/__init__.pyi‎

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
from collections.abc import Callable
1+
from .function_hooks import enabled_hooks as enabled_hooks
2+
from .import_hook import instrument_imports as instrument_imports
3+
from .instrument_bytecode import instrument_all as instrument_all, instrument_func as instrument_func
4+
from .native import (
5+
ALL_REMAINING as ALL_REMAINING,
6+
Fuzz as Fuzz,
7+
FuzzedDataProvider as FuzzedDataProvider,
8+
Mutate as Mutate,
9+
Setup as Setup,
10+
)
11+
from .utils import path as path
212

3-
def Setup(
4-
args: list[str],
5-
test_one_input: Callable[[bytes], None],
6-
**kwargs: bool | Callable[[bytes, int, int], str | bytes] | Callable[[bytes, bytes, int, int], str | bytes] | None,
7-
) -> list[str]: ...
8-
def Fuzz() -> None: ...
9-
def Mutate(data: bytes, max_size: int) -> bytes: ...
13+
def get_hook_dirs() -> list[str]: ... # undocumented

‎stubs/atheris/atheris/native.pyi‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
from collections.abc import Callable, Sequence
2+
from typing import Final, TypeVar
3+
4+
_T = TypeVar("_T")
5+
6+
ALL_REMAINING: Final[int] # undocumented
7+
8+
def Setup(
9+
args: Sequence[str],
10+
test_one_input: Callable[[bytes], None],
11+
/,
12+
**kwargs: bool | Callable[[bytes, int, int], str | bytes] | Callable[[bytes, bytes, int, int], str | bytes] | None,
13+
) -> list[str]: ...
14+
def Fuzz() -> None: ...
15+
def Mutate(data: bytes, max_size: int, /) -> bytes: ...
16+
17+
class FuzzedDataProvider:
18+
def __init__(self, data: bytes, /) -> None: ...
19+
def ConsumeUnicode(self, count: int) -> str: ...
20+
def ConsumeUnicodeNoSurrogates(self, count: int, /) -> str: ...
21+
def ConsumeBytes(self, count: int, /) -> bytes: ...
22+
def ConsumeString(self, count: int, /) -> str: ...
23+
def ConsumeInt(self, byte_size: int, /) -> int: ...
24+
def ConsumeUInt(self, byte_size: int, /) -> int: ...
25+
def ConsumeIntInRange(self, min: int, max: int, /) -> int: ...
26+
def ConsumeIntList(self, count: int, byte_size: int, /) -> list[int]: ...
27+
def ConsumeIntListInRange(self, count: int, min: int, max: int, /) -> list[int]: ...
28+
def ConsumeFloat(self) -> float: ...
29+
def ConsumeRegularFloat(self) -> float: ...
30+
def ConsumeProbability(self) -> float: ...
31+
def ConsumeFloatInRange(self, min: float, max: float, /) -> float: ...
32+
def ConsumeFloatList(self, count: int, /) -> list[float]: ...
33+
def ConsumeRegularFloatList(self, count: int, /) -> list[float]: ...
34+
def ConsumeProbabilityList(self, count: int, /) -> list[float]: ...
35+
def ConsumeFloatListInRange(self, count: int, min: float, max: float, /) -> list[float]: ...
36+
def PickValueInList(self, values: list[_T], /) -> _T: ...
37+
def ConsumeBool(self) -> bool: ...
38+
def remaining_bytes(self) -> int: ... # undocumented
39+
def buffer(self) -> bytes: ... # undocumented

0 commit comments

Comments
 (0)