mirror of https://github.com/astral-sh/ruff
Rewrite documentation for yield-in-init (#2748)
This commit is contained in:
parent
0040991778
commit
3d8fb5be20
|
|
@ -14,13 +14,15 @@ use crate::{
|
|||
define_violation!(
|
||||
/// ### What it does
|
||||
/// Checks for `__init__` methods that are turned into generators by the
|
||||
/// inclusion of `yield` or `yield from` statements.
|
||||
/// inclusion of `yield` or `yield from` expressions.
|
||||
///
|
||||
/// ### Why is this bad?
|
||||
/// The `__init__` method of a class is used to initialize new objects, not
|
||||
/// create them. As such, it should not return any value. By including a
|
||||
/// yield expression in the method turns it into a generator method. On
|
||||
/// calling, it will return a generator resulting in a runtime error.
|
||||
/// 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`. By including a `yield` or
|
||||
/// `yield from` expression in an `__init__`, the method will return a
|
||||
/// generator object when called at runtime, resulting in a runtime error.
|
||||
///
|
||||
/// ### Example
|
||||
/// ```python
|
||||
|
|
|
|||
|
|
@ -4,13 +4,15 @@ Derived from the **Pylint** linter.
|
|||
|
||||
### What it does
|
||||
Checks for `__init__` methods that are turned into generators by the
|
||||
inclusion of `yield` or `yield from` statements.
|
||||
inclusion of `yield` or `yield from` expressions.
|
||||
|
||||
### Why is this bad?
|
||||
The `__init__` method of a class is used to initialize new objects, not
|
||||
create them. As such, it should not return any value. By including a
|
||||
yield expression in the method turns it into a generator method. On
|
||||
calling, it will return a generator resulting in a runtime error.
|
||||
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`. By including a `yield` or
|
||||
`yield from` expression in an `__init__`, the method will return a
|
||||
generator object when called at runtime, resulting in a runtime error.
|
||||
|
||||
### Example
|
||||
```python
|
||||
|
|
|
|||
Loading…
Reference in New Issue