mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-03 18:28:24 +00:00
Respect runtime-required decorators on functions (#9317)
## Summary This PR modifies the semantics of `runtime-evaluated-decorators` to respect decorators on both classes _and_ functions. Historically, this only respected classes, since the common use-case is (e.g.) `pydantic.BaseModel` -- but functions are equally valid. Closes https://github.com/astral-sh/ruff/issues/9312. ## Test Plan `cargo test`
This commit is contained in:
parent
97e9d3c54f
commit
94727996e8
7 changed files with 92 additions and 31 deletions
|
@ -1632,13 +1632,16 @@ pub struct Flake8TypeCheckingOptions {
|
|||
)]
|
||||
pub runtime_evaluated_base_classes: Option<Vec<String>>,
|
||||
|
||||
/// Exempt classes decorated with any of the enumerated decorators from
|
||||
/// needing to be moved into type-checking blocks.
|
||||
/// Exempt classes and functions decorated with any of the enumerated
|
||||
/// decorators from being moved into type-checking blocks.
|
||||
///
|
||||
/// Common examples include Pydantic's `@pydantic.validate_call` decorator
|
||||
/// (for functions) and attrs' `@attrs.define` decorator (for classes).
|
||||
#[option(
|
||||
default = "[]",
|
||||
value_type = "list[str]",
|
||||
example = r#"
|
||||
runtime-evaluated-decorators = ["attrs.define", "attrs.frozen"]
|
||||
runtime-evaluated-decorators = ["pydantic.validate_call", "attrs.define"]
|
||||
"#
|
||||
)]
|
||||
pub runtime_evaluated_decorators: Option<Vec<String>>,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue