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: 21 rules found
bad-practice
    Impact
      Clean code attribute
        1. Any should not be used as a type hint

           Code Smell
        2. Tests should be skipped explicitly

           Code Smell
        3. Builtins should not be shadowed by local variables

           Code Smell
        4. "SystemExit" should be re-raised

           Code Smell
        5. Property getter, setter and deleter methods should have the expected number of parameters

           Bug
        6. Special methods should have an expected number of parameters

           Bug
        7. Function parameters' default values should not be modified or assigned

           Code Smell
        8. Boolean expressions of exceptions should not be used in "except" statements

           Bug
        9. A subclass should not be in the same "except" statement as a parent class

           Code Smell
        10. Some special methods should return "NotImplemented" instead of raising "NotImplementedError"

           Code Smell
        11. Custom Exception classes should inherit from "Exception" or one of its subclasses

           Code Smell
        12. Special method "__exit__" should not re-raise the provided exception

           Code Smell
        13. Walrus operator should not make code confusing

           Code Smell
        14. Cipher Block Chaining IVs should be unpredictable

           Vulnerability
        15. Using non-standard cryptographic algorithms is security-sensitive

           Security Hotspot
        16. Wildcard imports should not be used

           Code Smell
        17. Formatting SQL queries is security-sensitive

           Security Hotspot
        18. Loops with at most one iteration should be refactored

           Bug
        19. A reason should be provided when skipping a test

           Code Smell
        20. Using hardcoded IP addresses is security-sensitive

           Security Hotspot
        21. Track uses of "NOSONAR" comments

           Code Smell

        Some special methods should return "NotImplemented" instead of raising "NotImplementedError"

        intentionality - complete
        maintainability
        Code Smell
        Quick FixIDE quick fixes available with SonarQube for IDE
        • error-handling
        • bad-practice

        This rule raises an issue when a special method raises a NotImplementedError instead of returning NotImplemented.

        Why is this an issue?

        How can I fix it?

        More Info

        In Python, special methods corresponding to numeric operators and rich comparison operators should return NotImplemented when the operation is not supported.

        For example A + B is equivalent to calling A.__add__(B). If this binary operation is not supported by class A, A.__add__(B) should return NotImplemented. The interpreter will then try the reverse operation, i.e. B.__radd__(A). If these special methods were to raise NotImplementedError, the callers would not catch the exception and the reverse operation would not be called.

        Below is the list of special methods this rule applies to:

        • __lt__(self, other)
        • __le__(self, other)
        • __eq__(self, other)
        • __ne__(self, other)
        • __gt__(self, other)
        • __ge__(self, other)
        • __add__(self, other)
        • __sub__(self, other)
        • __mul__(self, other)
        • __matmul__(self, other)
        • __truediv__(self, other)
        • __floordiv__(self, other)
        • __mod__(self, other)
        • __divmod__(self, other)
        • __pow__(self, other[, modulo])
        • __lshift__(self, other)
        • __rshift__(self, other)
        • __and__(self, other)
        • __xor__(self, other)
        • __or__(self, other)
        • __radd__(self, other)
        • __rsub__(self, other)
        • __rmul__(self, other)
        • __rmatmul__(self, other)
        • __rtruediv__(self, other)
        • __rfloordiv__(self, other)
        • __rmod__(self, other)
        • __rdivmod__(self, other)
        • __rpow__(self, other[, modulo])
        • __rlshift__(self, other)
        • __rrshift__(self, other)
        • __rand__(self, other)
        • __rxor__(self, other)
        • __ror__(self, other)
        • __iadd__(self, other)
        • __isub__(self, other)
        • __imul__(self, other)
        • __imatmul__(self, other)
        • __itruediv__(self, other)
        • __ifloordiv__(self, other)
        • __imod__(self, other)
        • __ipow__(self, other[, modulo])
        • __ilshift__(self, other)
        • __irshift__(self, other)
        • __iand__(self, other)
        • __ixor__(self, other)
        • __ior__(self, other)
        • __length_hint__(self)
          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
          9.1
        • SonarQube ServerAnalyze code in your
          on-premise CI
          Developer Edition
          Available Since
          9.1

        © 2026 SonarSource Sàrl. All rights reserved.

        Privacy Policy | Cookie Policy | Terms of Use