org.sonar.l10n.py.rules.python.S6882.html Maven / Gradle / Ivy
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
- Python documentation - datetime
© 2015 - 2024 Weber Informatics LLC | Privacy Policy