diff --git a/crates/ruff/src/rules/pylint/rules/return_in_init.rs b/crates/ruff/src/rules/pylint/rules/return_in_init.rs index d2fcd76f498a40..c6bae96044a6dc 100644 --- a/crates/ruff/src/rules/pylint/rules/return_in_init.rs +++ b/crates/ruff/src/rules/pylint/rules/return_in_init.rs @@ -10,6 +10,25 @@ use crate::violation::Violation; use super::yield_in_init::in_dunder_init; define_violation!( + /// ## What it does + /// Checks for `__init__` methods that return values. + /// + /// ## Why is this bad? + /// The `__init__` method is the constructor for a given Python class, + /// responsible for initializing, rather than creating, new objects. + /// + /// The `__init__` method has to return `None`. If it returns `self` or any + /// other objects, this results in a runtime error. + /// + /// ## Example + /// ```python + /// class InitReturnsValue: + /// def __init__(self, i): + /// return [] + /// ``` + /// + /// ## References + /// * [CodeQL: `py-explicit-return-in-init`](https://codeql.github.com/codeql-query-help/python/py-explicit-return-in-init/) pub struct ReturnInInit; ); impl Violation for ReturnInInit { diff --git a/ruff.schema.json b/ruff.schema.json index 2a203158d572c4..08818807cde193 100644 --- a/ruff.schema.json +++ b/ruff.schema.json @@ -1754,6 +1754,7 @@ "PLE01", "PLE010", "PLE0100", + "PLE0101", "PLE011", "PLE0117", "PLE0118",