Skip to content

False positive: too-many-statements-in-try-clause triggers on try-finally clause #25390

@PerchunPak

Description

@PerchunPak

Summary

https://docs.astral.sh/ruff/rules/too-many-statements-in-try-clause/

Sometimes, it is easier to write try-finally clauses instead of context managers. Especially if the object is not a context manager, or we need to do other clean-up steps than session.close(). Anyway, this rule should not be triggered on a try-finally clause

session = ...
try:
    print()
    print()
    print()
    print()
    print()
    print()
finally:
    session.close()

Playground

Version

0.15.14

Metadata

Metadata

Assignees

Labels

previewRelated to preview mode featuresruleImplementing or modifying a lint rule

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions