Skip to content

ANN201 Incorrect autofix return type for raise in loop #22315

@spaceby

Description

@spaceby

Summary

https://play.ruff.rs/f2c7c8a3-1e38-425f-b1e5-0068e6f8b67b

class Test:
    items_list = []

    def method(self):
        for item in self.items_list:
            raise Exception(item)


t = Test()
t.method()

This code returns None.
However, autofix substitutes in method NoReturn

from typing import NoReturn
class Test:
    items_list = []

    def method(self) -> NoReturn:
        for item in self.items_list:
            raise Exception(item)


t = Test()
t.method()

Version

0.14.10

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingtype-inferenceRequires more advanced type inference.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions