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: 6 rules found
pep
    Impact
      Clean code attribute
        1. 'startswith' or 'endswith' methods should be used instead of string slicing in condition expressions

           Code Smell
        2. Caught Exceptions must derive from BaseException

           Bug
        3. Exceptions' "__cause__" should be either an Exception or None

           Bug
        4. Walrus operator should not make code confusing

           Code Smell
        5. "__iter__" should return an iterator

           Bug
        6. Function names should comply with a naming convention

           Code Smell

        "__iter__" should return an iterator

        intentionality - logical
        reliability
        Bug
        • python3
        • pep

        This rule raises an issue when the object returned by __iter__ is not a valid iterator.

        Why is this an issue?

        How can I fix it?

        More Info

        An iterable object is an object capable of returning its members one at a time. To do so, it must define an __iter__ method that returns an iterator.

        The iterator protocol specifies that, in order to be a valid iterator, an object must define a __next__ and an __iter__ method (because iterators are also iterable).

        Defining an __iter__ method that returns anything else than an iterator will raise a TypeError as soon as the iteration begins.

        Note that generators and generator expressions have both __next__ and __iter__ methods generated automatically.

          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 Community BuildAnalyze code in your
          on-premise CI
          Available Since
          10.2
        • SonarQube ServerAnalyze code in your
          on-premise CI
          Developer Edition
          Available Since
          10.2

        © 2026 SonarSource Sàrl. All rights reserved.

        Privacy Policy | Cookie Policy | Terms of Use