Add pydocstyle to the ruff rules (#52136)

Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
Signed-off-by: Harry Mellor <hej.mellor@gmail.com>
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Harry Mellor
2026-09-16 16:44:29 +00:00
committed by GitHub
co-authored by Claude Opus 5
parent 804e5377aa
commit 8c1557a79c
2002 changed files with 15024 additions and 14269 deletions
@@ -161,7 +161,6 @@ class GuidanceGrammar(StructuredOutputGrammar):
Returns True if the parser was advanced successfully.
Returns False if the parser failed to advance.
"""
if self.ll_tokenizer.eos_token in tokens:
if self.ll_matcher.is_stopped() and not self.terminated:
self.rollback_lag = 1
@@ -283,7 +283,7 @@ def _prefix_needs_context(parsed) -> bool:
def _check_unsupported(parsed) -> None:
"""Check for regex features unsupported by regex-automata"""
"""Check for regex features unsupported by regex-automata."""
tokens = parsed.data if hasattr(parsed, "data") else parsed
for ttype, tval in tokens:
# backreference
@@ -310,8 +310,7 @@ def _check_unsupported(parsed) -> None:
def validate_regex_is_buildable(pattern: str) -> None:
"""
Validates that the input regex is not using unsupported features
"""Validates that the input regex is not using unsupported features
of the `regex-automata` crate (outlines_core regex engine) and has a
universal start state.
definition of universal start state used can be found at:
+16 -20
View File
@@ -33,8 +33,7 @@ class StructuredOutputGrammar(ABC):
@abstractmethod
def accept_tokens(self, request_id: str, tokens: list[int]) -> bool:
"""
Determines whether the provided tokens are accepted for the
"""Determines whether the provided tokens are accepted for the
given request.
Args:
@@ -43,12 +42,12 @@ class StructuredOutputGrammar(ABC):
Returns:
bool: True if the tokens are accepted, False otherwise.
"""
@abstractmethod
def validate_tokens(self, tokens: list[int]) -> list[int]:
"""
Validates the provided tokens against the grammar.
"""Validates the provided tokens against the grammar.
Will not advance the FSM.
Args:
@@ -57,42 +56,41 @@ class StructuredOutputGrammar(ABC):
Returns:
list[int]: A list of accepted token IDs. Will be a prefix
of the input tokens, and empty if none are accepted.
"""
@abstractmethod
def rollback(self, num_tokens: int) -> None:
"""
Rolls back the state of the grammar by a specified number of tokens.
"""Rolls back the state of the grammar by a specified number of tokens.
Will also revert counters for the number of processed tokens.
Args:
num_tokens (int): The number of tokens to roll back.
"""
@abstractmethod
def fill_bitmask(self, bitmask: "torch.Tensor", batch_index: int) -> None:
"""
Fills the bitmask for a specific batch index.
"""Fills the bitmask for a specific batch index.
Args:
bitmask (torch.Tensor): The bitmask to fill
batch_index (int): The index in the bitmask to fill
"""
@abstractmethod
def is_terminated(self) -> bool:
"""
Checks whether the structured output process has terminated.
"""Checks whether the structured output process has terminated.
Returns:
bool: True if the process is terminated, False otherwise.
"""
@abstractmethod
def reset(self):
"""
Resets the state of the structured output grammar.
"""
"""Resets the state of the structured output grammar."""
@dataclass
@@ -110,8 +108,7 @@ class StructuredOutputBackend(ABC):
grammar_spec: str,
stop_token_ids: set[int] | None = None,
) -> StructuredOutputGrammar:
"""
Compiles a grammar specification into a structured output grammar.
"""Compiles a grammar specification into a structured output grammar.
Args:
request_type (StructuredOutputOptions): The type of structured
@@ -123,20 +120,19 @@ class StructuredOutputBackend(ABC):
Returns:
StructuredOutputGrammar: The compiled structured output grammar.
"""
@abstractmethod
def allocate_token_bitmask(self, max_num_seqs: int) -> "torch.Tensor":
"""
Allocates a token bitmask for the specified maximum number of sequences.
"""Allocates a token bitmask for the specified maximum number of sequences.
Args:
max_num_seqs (int): The maximum number of sequences for which
to allocate the bitmask.
"""
@abstractmethod
def destroy(self):
"""
Backend-specific cleanup.
"""
"""Backend-specific cleanup."""
+12 -11
View File
@@ -74,6 +74,7 @@ def compile_regex_with_timeout(fn: Callable[[str], _T], pattern: str) -> _T:
Raises:
ValueError: If compilation exceeds the configured timeout.
"""
timeout = envs.VLLM_REGEX_COMPILATION_TIMEOUT_S
if timeout <= 0:
@@ -103,13 +104,14 @@ def apply_grammar_bitmask(
input_batch: InputBatch,
logits: torch.Tensor,
) -> None:
"""
Apply grammar bitmask to output logits of the model with xgrammar function.
"""Apply grammar bitmask to output logits of the model with xgrammar function.
Args:
scheduler_output (SchedulerOutput): The result of engine scheduling.
grammar_output (GrammarOutput): The grammar bitmask to apply.
input_batch (InputBatch): The input of model runner.
logits (torch.Tensor): The output logits of model forward.
"""
# Serialization of np.ndarray is much more efficient than a tensor,
# so we receive it in that format.
@@ -190,8 +192,7 @@ def apply_grammar_bitmask(
class OutlinesVocabulary:
"""
Wrapper class for `outlines_core.Vocabulary`,
"""Wrapper class for `outlines_core.Vocabulary`,
which allows us to store a hash with the vocabulary
"""
@@ -206,7 +207,7 @@ class OutlinesVocabulary:
def get_outlines_cache_path() -> str:
"""Get the context object that contains previously-computed return values"""
"""Get the context object that contains previously-computed return values."""
outlines_cache_dir = os.getenv("OUTLINES_CACHE_DIR")
xdg_cache_home = os.getenv("XDG_CACHE_HOME")
home_dir = os.path.expanduser("~")
@@ -294,8 +295,7 @@ class OutlinesDiskCache:
def get_outlines_cache():
"""Get the Cache instance to be used for index caching"""
"""Get the Cache instance to be used for index caching."""
cache_dir = get_outlines_cache_path()
if envs.VLLM_V1_USE_OUTLINES_CACHE:
logger.warning(
@@ -324,6 +324,7 @@ def _reduced_vocabulary(tokenizer: TokenizerLike) -> dict[bytes, list[int]]:
Returns:
A Dict of token string -> equivalent token ids
"""
eos_token_id = tokenizer.eos_token_id
@@ -403,8 +404,7 @@ def get_outlines_vocabulary(tokenizer: TokenizerLike) -> oc.Vocabulary:
def grammar_is_likely_lark(grammar_str: str) -> bool:
"""
Check if grammar appears to use Lark syntax.
"""Check if grammar appears to use Lark syntax.
Args:
grammar_str: Input grammar string
@@ -417,6 +417,7 @@ def grammar_is_likely_lark(grammar_str: str) -> bool:
True
>>> grammar_is_likely_lark("rule ::= 'abc'")
False
"""
if not grammar_str or not isinstance(grammar_str, str):
return False
@@ -435,8 +436,7 @@ def grammar_is_likely_lark(grammar_str: str) -> bool:
def convert_lark_to_ebnf(grammar_str: str) -> str:
"""
Convert a Lark grammar string to EBNF format.
"""Convert a Lark grammar string to EBNF format.
EBNF reference:
https://github.com/ggerganov/llama.cpp/blob/master/grammars/README.md
@@ -453,6 +453,7 @@ def convert_lark_to_ebnf(grammar_str: str) -> str:
>>> print(convert_lark_to_ebnf("rule: 'hello'"))
root ::= rule
rule ::= "hello"
"""
if not isinstance(grammar_str, str):
raise ValueError(f"Grammar must be a string, got {type(grammar_str)}")