All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sonar.l10n.py.rules.python.S6882.html Maven / Gradle / Ivy

There is a newer version: 4.23.0.17664
Show newest version

This rule raises an issue when an incorrect value is set as an attribute of datetime.date, datetime.time, or datetime.datetime

Why is this an issue?

Setting a date attribute value with a value which is out of the range of possible values will lead to a ValueError.

How to fix it

Set attribute values with values that are within the range of possible values.

Code examples

Noncompliant code example

def foo():
    dt = datetime(year=2024, day=66, month=1, hour=16, minute=1) # ValueError: day is out of range for month

Compliant solution

def foo():
    dt = datetime(year=2024, day=1, month=1, hour=16, minute=1)

Resources

Documentation





© 2015 - 2024 Weber Informatics LLC | Privacy Policy