-
Notifications
You must be signed in to change notification settings - Fork 2k
Open
Labels
acceptedReady for implementationReady for implementationruleImplementing or modifying a lint ruleImplementing or modifying a lint rule
Description
Ruff produces useful errors for dataclasses. Recently, PEP 681 added the ability to define custom dataclasses. However, Ruff doesn't treat these as dataclasses and produces no errors:
from dataclasses import field
import dataclasses as dc
from collections.abc import Callable
from typing import Any, TypeVar
from typing_extensions import dataclass_transform
_T = TypeVar('_T')
def model_field(*,
default: None | Any = ...,
resolver: None | Callable[[], Any] = None,
init: bool = True
) -> Any:
return field(default=default, init=init)
@dataclass_transform(
kw_only_default=True,
field_specifiers=(model_field,))
def create_model(*,
init: bool = True,
) -> Callable[[type[_T]], type[_T]]:
return dc.dataclass(init=init)
def f(x: int) -> int:
return x + 1
@create_model(init=False)
class CustomerModel:
a: int = model_field(resolver=lambda: 0) # Should be fine: model_field is a field specifier
b: int = f(1) # Should give RUF009
c = CustomerModel()Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
acceptedReady for implementationReady for implementationruleImplementing or modifying a lint ruleImplementing or modifying a lint rule