rspec/rules/S6882/python/rule.adoc

36 lines
1004 B
Plaintext
Raw Normal View History

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
[source,python,diff-id=1,diff-type=noncompliant]
----
def foo():
dt = datetime(year=2024, day=66, month=1, hour=16, minute=1) # ValueError: day is out of range for month
----
==== Compliant solution
[source,python,diff-id=1,diff-type=compliant]
----
def foo():
dt = datetime(year=2024, day=1, month=1, hour=16, minute=1)
----
== Resources
=== Documentation
* Python documentation - https://docs.python.org/3/library/datetime.html#[datetime]
//=== Articles & blog posts
//=== Conference presentations
//=== Standards
//=== External coding guidelines
//=== Benchmarks