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: 7 rules found
datetime
    Impact
      Clean code attribute
        1. Using timezone-aware "datetime" objects should be preferred over using "datetime.datetime.utcnow" and "datetime.datetime.utcfromtimestamp"

           Code Smell
        2. Numpy weekmask should have a valid value

           Code Smell
        3. Dates should be formatted correctly when using "pandas.to_datetime" with "dayfirst" or "yearfirst" arguments

           Code Smell
        4. "zoneinfo" should be preferred to "pytz" when using Python 3.9 and later

           Code Smell
        5. "pytz.timezone" should not be passed to the "datetime.datetime" constructor

           Code Smell
        6. The 12-hour format should be used with the AM/PM marker, otherwise the 24-hour format should be used

           Code Smell
        7. Constructor attributes of date and time objects should be in the range of possible values

           Code Smell

        The 12-hour format should be used with the AM/PM marker, otherwise the 24-hour format should be used

        consistency - conventional
        maintainability
        reliability
        Code Smell
        • datetime

        This rule raises an issue when a date format string has the 24-hour code with the AM/PM marker or the 12-hour code without the AM/PM marker.

        Why is this an issue?

        How can I fix it?

        More Info

        The %p directive in the strftime method is used to represent the AM/PM marker in a time string. It is commonly used in conjunction with the %I directive, which represents the hour in a 12-hour clock.

        Using the 24-hour format directive with an AM/PM marker can lead to unwanted results e.g.:

        time_string = time(16,0).strftime("%H:%M %p")
        print(time_string)
        

        will print 16:00 PM which makes no sense.

        On the other hand the AM/PM marker is needed when the 12-hour format directive is used to show complete information about an hour e.g.:

        time_string = time(16,0).strftime("%I:%M")
        print(time_string)
        

        will print 04:00 without indicating if the time is in the morning or the afternoon.

          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.5
        • SonarQube ServerAnalyze code in your
          on-premise CI
          Developer Edition
          Available Since
          10.5

        © 2026 SonarSource Sàrl. All rights reserved.

        Privacy Policy | Cookie Policy | Terms of Use