Skip to content

RET504 for yield #13141

@opk12

Description

@opk12

Hi, Python newbie here. test_return() warns about unnecessary assignment before return, so I was wondering, what about the same, but for yield?

$  cat a.py 
import math


def test_return() -> int:
    """Test `return`."""
    for size in range(1, 10):
        content = math.sqrt(size)
        return content


def test_yield() -> int:
    """Test `yield`."""
    for size in range(1, 10):
        content = math.sqrt(size)
        yield content
$    ruff check .  --select ALL --isolated
warning: `one-blank-line-before-class` (D203) and `no-blank-line-before-class` (D211) are incompatible. Ignoring `one-blank-line-before-class`.
warning: `multi-line-summary-first-line` (D212) and `multi-line-summary-second-line` (D213) are incompatible. Ignoring `multi-line-summary-second-line`.
a.py:1:1: D100 Missing docstring in public module
a.py:6:5: RET503 [*] Missing explicit `return` at the end of function able to return non-`None` value
a.py:8:16: RET504 [*] Unnecessary assignment to `content` before `return` statement
Found 3 errors.
[*] 2 potentially fixable with the --fix option.
$  # Debian sid
$  ruff --version
ruff 0.0.291

Metadata

Metadata

Labels

acceptedReady for implementationruleImplementing or modifying a lint rule

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions