datetime-now-usage
datetime.now() makes code non-deterministic and hard to test
Applies to: Go, JavaScript, Python, Ruby, Rust, TypeScript
Why this matters
Using datetime.now() directly makes your code depend on the current time, which makes tests unreliable and caching impossible. Inject the time as a parameter or use a clock abstraction that can be mocked.
Catch it before it ships
pip install stablestack # or: npx stablestackstablestack # scans your project, DET006 includedstablestack explain DET006DET006 is part of the Pro rule set. See pricing — the free tier ships 24 checks with no signup.
False positive in your codebase? Suppress a single line with # noqa: DET006
More Determinism checks
unsorted-dict-iteration
Dictionary iteration without a canonical sort order
DET002unsorted-set-iteration
Set iteration without sorting can produce unpredictable order
DET003missing-sort-tiebreaker
Sorting by a single field without tiebreaker can produce unstable order
DET004list-set-dedup
Using list(set(...)) for deduplication scrambles element order
DET005random-without-seed
Random values without seed cause non-reproducible behavior
DET007unsorted-directory-listing
Directory listings have no guaranteed order across systems
DET008hash-unsorted-collection
Hashing dicts/sets without sorting produces inconsistent cache keys
DET009uncached-llm-call
LLM API call without @cache decorator wastes money on duplicate requests