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:
Charlie Marsh 2023-12-29 22:14:53 -04:00 committed by GitHub
parent 97e9d3c54f
commit 94727996e8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 92 additions and 31 deletions

View file

@ -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>>,