SonarSource Rules
  • Products

    In-IDE

    Code Quality and Security in your IDE with SonarQube Ide

    IDE extension that lets you fix coding issues before they exist!

    Discover SonarQube for IDE

    SaaS

    Code Quality and Security in the cloud with SonarQube Cloud

    Setup is effortless and analysis is automatic for most languages

    Discover SonarQube Cloud

    Self-Hosted

    Code Quality and Security Self-Hosted with SonarQube Server

    Fast, accurate analysis; enterprise scalability

    Discover SonarQube Server
  • SecretsSecrets
  • ABAPABAP
  • AnsibleAnsible
  • ApexApex
  • AzureResourceManagerAzureResourceManager
  • CC
  • C#C#
  • C++C++
  • CloudFormationCloudFormation
  • COBOLCOBOL
  • CSSCSS
  • DartDart
  • DockerDocker
  • FlexFlex
  • GitHub ActionsGitHub Actions
  • GoGo
  • GroovyGroovy
  • HTMLHTML
  • JavaJava
  • JavaScriptJavaScript
  • JSONJSON
  • JCLJCL
  • KotlinKotlin
  • KubernetesKubernetes
  • Objective CObjective C
  • PHPPHP
  • PL/IPL/I
  • PL/SQLPL/SQL
  • PythonPython
  • RPGRPG
  • RubyRuby
  • RustRust
  • ScalaScala
  • ShellShell
  • SwiftSwift
  • TerraformTerraform
  • TextText
  • TypeScriptTypeScript
  • T-SQLT-SQL
  • VB.NETVB.NET
  • VB6VB6
  • XMLXML
  • YAMLYAML
Python

Python static code analysis

Unique rules to find Bugs, Vulnerabilities, Security Hotspots, and Code Smells in your PYTHON code

  • All rules 414
  • Vulnerability45
  • Bug104
  • Security Hotspot50
  • Code Smell215

  • Quick Fix 33
Filtered: 17 rules found
async
    Impact
      Clean code attribute
        1. "async with" should be used for asynchronous resource management

           Bug
        2. Control flow statements should not be used inside TaskGroup or Nursery blocks

           Bug
        3. TaskGroup/Nursery should not be used for a single start call

           Code Smell
        4. Async functions should use async features

           Code Smell
        5. Asyncio tasks should be saved to prevent premature garbage collection

           Bug
        6. Async functions should not contain input() calls

           Bug
        7. Async functions should not contain synchronous HTTP client calls

           Bug
        8. Cancellation exceptions should be re-raised after cleanup

           Bug
        9. Async functions should not contain synchronous file operations

           Bug
        10. Checkpoints should be used instead of sleep(0)

           Code Smell
        11. Cancellation scopes should contain checkpoints

           Bug
        12. Async functions should not contain synchronous OS calls

           Bug
        13. Use non-blocking sleep functions in asynchronous code

           Bug
        14. Async functions should not contain synchronous subprocess calls

           Bug
        15. Long sleep durations should use sleep_forever() instead of arbitrary intervals

           Code Smell
        16. Events should be used instead of `sleep` in asynchronous loops

           Code Smell
        17. Asynchronous functions should not accept timeout parameters

           Code Smell

        Cancellation exceptions should be re-raised after cleanup

        intentionality - logical
        maintainability
        reliability
        Bug
        • async
        • asyncio
        • trio
        • anyio

        This rule raises an issue when a cancellation excception is caught without re-raising it.

        Why is this an issue?

        How can I fix it?

        More Info

        Asynchronous frameworks like asyncio, trio, and anyio use special exceptions to signal that a task or operation should be cancelled. These exceptions are not typical errors indicating a logical flaw in the task but are directives for the task to terminate its execution prematurely and perform necessary cleanup.

        When a task is cancelled, the framework typically injects this cancellation exception into it. The task is expected to:

        • Catch this specific cancellation exception.
        • Perform any urgent and brief cleanup actions (e.g., releasing locks or other resources).
        • Re-raise the cancellation exception.

        If a cancellation exception is caught and not re-raised (e.g., it’s suppressed with a pass statement, only logged, the handler returns normally, or a different exception is raised instead), the cancellation signal is effectively "swallowed".

        This prevents the framework and any calling code from knowing that the task has acknowledged the cancellation and is stopping. The task might even continue running parts of its code after the except block, which is contrary to the purpose of cancellation.

        Properly propagating cancellation exceptions is crucial for the cooperative multitasking model these frameworks rely on.

        What is the potential impact?

        Suppressing cancellation exceptions can lead to significant problems:

        • Unresponsive Applications: Tasks ignoring cancellation may run indefinitely, making the application unresponsive to shutdown signals.
        • Resource Leaks: Tasks not stopping properly can leave resources (files, connections, locks) unreleased, leading to resource exhaustion.
        • Incorrect State: Partial execution of cancelled operations can leave the application in an inconsistent state, risking data corruption.
        • Debugging Difficulties: Troubleshooting why tasks continue running or why shutdown fails becomes challenging.
        • Broken Abstractions: Reliable cancellation is essential for async patterns and libraries; ignoring it breaks timeouts and task groups.
          Available In:
        • SonarQube IdeCatch issues on the fly,
          in your IDE
        • SonarQube CloudDetect issues in your GitHub, Azure DevOps Services, Bitbucket Cloud, GitLab repositories
        • SonarQube ServerAnalyze code in your
          on-premise CI

        © 2026 SonarSource Sàrl. All rights reserved.

        Privacy Policy | Cookie Policy | Terms of Use