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
+14 -14
View File
@@ -64,7 +64,9 @@ def config(
cls: The class to decorate
config: The pydantic ConfigDict to use. If provided, it will be merged with
the default config.
**kwargs: Additional arguments to pass to pydantic.dataclass."""
**kwargs: Additional arguments to pass to pydantic.dataclass.
"""
# Extra fields are forbidden by default
merged_config = ConfigDict(extra="forbid")
if config is not None:
@@ -82,7 +84,8 @@ def config(
def get_field(cls: ConfigType, name: str) -> Any:
"""Get the default factory field of a dataclass by name. Used for getting
default factory fields in `EngineArgs`."""
default factory fields in `EngineArgs`.
"""
if not is_dataclass(cls):
raise TypeError("The given class is not a dataclass.")
try:
@@ -119,7 +122,8 @@ def is_init_field(cls: ConfigType, name: str) -> bool:
def replace(dataclass_instance: ConfigT, /, **kwargs) -> ConfigT:
"""Like [`dataclasses.replace`](https://docs.python.org/3/library/dataclasses.html#dataclasses.replace),
but compatible with Pydantic dataclasses which use `pydantic.fields.Field` instead
of `dataclasses.field`"""
of `dataclasses.field`
"""
cls = type(dataclass_instance)
dataclass_dict = dataclass_instance.__dict__
dataclass_dict = {k: v for k, v in dataclass_dict.items() if is_init_field(cls, k)}
@@ -134,8 +138,7 @@ def getattr_iter(
default_factory: Callable[[], Any] | None = None,
warn: bool = False,
) -> Any:
"""
A helper function that retrieves an attribute from an object which may
"""A helper function that retrieves an attribute from an object which may
have multiple possible names. This is useful when fetching attributes from
arbitrary `transformers.PretrainedConfig` instances.
@@ -158,12 +161,10 @@ def getattr_iter(
def get_attr_docs(cls: type[Any]) -> dict[str, str]:
"""
Get any docstrings placed after attribute assignments in a class body.
"""Get any docstrings placed after attribute assignments in a class body.
https://davidism.com/mit-license/
"""
cls_node = ast.parse(textwrap.dedent(inspect.getsource(cls))).body[0]
if not isinstance(cls_node, ast.ClassDef):
@@ -385,8 +386,7 @@ def hash_factors(items: dict[str, object]) -> str:
@dataclass
class Range:
"""
A range of numbers.
"""A range of numbers.
Inclusive of start, inclusive of end.
"""
@@ -445,8 +445,7 @@ def get_from_deprecated_env_if_set(
removal_version: str,
field_name: str | None = None,
) -> str | None:
"""
Get value from deprecated environment variable with warning.
"""Get value from deprecated environment variable with warning.
Args:
env_name: Name of the deprecated environment variable
@@ -455,6 +454,7 @@ def get_from_deprecated_env_if_set(
Returns:
The environment variable value if set, None otherwise
"""
if envs.is_set(env_name):
value = os.environ.get(env_name)
@@ -477,8 +477,7 @@ def set_from_deprecated_env_if_set(
to_bool: bool = False,
to_int: bool = False,
) -> None:
"""
Set object field from deprecated environment variable with warning.
"""Set object field from deprecated environment variable with warning.
Args:
config: Config object to set the field on
@@ -489,6 +488,7 @@ def set_from_deprecated_env_if_set(
to_int: Whether to convert the environment variable value to integer
Returns:
None
"""
if to_bool and to_int:
raise ValueError("Cannot convert to both boolean and integer.")