Repository navigation
Backlog
Labels
extension-modulesC modules in the Modules dirstdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error
Description
| BPO | 23607 |
|---|---|
| Nosy | @malemburg, @abalkin, @vstinner, @skrah, @serhiy-storchaka, @pganssle, @shlomoa, @remilapeyre |
| Files |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee = 'https://github.com/serhiy-storchaka'
closed_at = None
created_at = <Date 2015-03-08.10:35:01.714>
labels = ['3.8', 'type-bug', 'library']
title = 'Inconsistency in datetime.utcfromtimestamp(Decimal)'
updated_at = <Date 2019-02-27.17:14:23.100>
user = 'https://github.com/serhiy-storchaka'bugs.python.org fields:
activity = <Date 2019-02-27.17:14:23.100>
actor = 'remi.lapeyre'
assignee = 'serhiy.storchaka'
closed = False
closed_date = None
closer = None
components = ['Library (Lib)']
creation = <Date 2015-03-08.10:35:01.714>
creator = 'serhiy.storchaka'
dependencies = []
files = ['38388', '38736']
hgrepos = []
issue_num = 23607
keywords = ['patch']
message_count = 11.0
messages = ['237527', '237541', '237801', '239593', '239595', '239597', '239608', '239613', '336769', '336771', '336772']
nosy_count = 10.0
nosy_names = ['lemburg', 'belopolsky', 'vstinner', 'SilentGhost', 'skrah', 'serhiy.storchaka', 'p-ganssle', 'anglister', 'remi.lapeyre', 'Steven Davidson']
pr_nums = []
priority = 'low'
resolution = None
stage = 'patch review'
status = 'open'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue23607'
versions = ['Python 3.8']Linked PRs
- gh-67795: Accept any real numbers as timestamp and timeout #139224
- gh-67795: Improve precision of non-float timestamp and timeout arguments #139273
- gh-67795: Skip test values below the time_t minimum on platforms with 32-bit time_t #162878
- gh-67795: Add pytime_double_to_time_t() helper function #162904
- gh-67795: Remove _PyTime_FromSecondsDouble() function #162906
- gh-67795: Rewrite pytime_from_pyfloat() #162940
Metadata
Metadata
Assignees
Labels
extension-modulesC modules in the Modules dirstdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error
Projects
- StatusShow more project fieldsDone
Activity
serhiy-storchaka commentedon Feb 27, 2019
No, the bug is not fixed, and this is not easy issue. You should use non-integer Decimals to reproduce it. In 3.8 this emits a deprecation warning:
StanFromIreland commentedon Jul 9, 2025
Ironically it is the opposite now.
Furthermore,
utcfromtimestampis deprecated, and it seems no one has actually used this, since I can find no complaints, I propose we simply close this effort. Only accepting int/float is fine, converting aDecimalis not difficult.pythongh-67795: Accept any real numbers as timestamp and timeout
serhiy-storchaka commentedon Sep 22, 2025
I only used
utcfromtimestamp()in examples because it produces the same result independently from the time zone. All of the above is applied tofromtimestamp()too.The original issue was because the C code first checked if the argument is
float, and used conversion to int (which called__int__) for other types. Now__int__no longer called in implicit conversion to int, so we get a TypeError instead of truncation.On other hand, the Python code now uses different method to split a number on the integer and fractional parts --
math.modf(). It accepts any real numbers and converts them to float.This is a one of rare cases where float is accepted, but other real numbers are not. Usually, real numbers are implicitly converted to float if float is accepted. It is not so difficult to make any real numbers be accepted as timestamp and timeout arguments which will be implicitly converted to floats. Although using more precise numbers will not improve precision. The hard part is updating documentation and adding many new tests for functions that directly use such conversion. #139224 implements this part.
Preserving precision of more precise numbers is more difficult task. My initial patch tried to do this by using arithmetic operations on precise numbers, for example, the fractional part can be calculated as
t - int(t)ort % 1. It works iff all operations on more precise numbers has comparable precision. Unfortunately, for Decimal the result of arithmetic operation depends on the local context, not on the precision of operands. It is also no longer work because the half-to-even rounding is now used for timestamp, it is more difficult to implement.Other way -- using
as_integer_ratio()(ornumeratoranddenumerator) to represent the number as rational, and then perform exact operations on rationals.gh-67795: Accept any real numbers as timestamp and timeout (GH-139224)
pythongh-67795: Improve precision of non-float timestamp and timeout …
serhiy-storchaka commentedon Sep 23, 2025
#139273 implements the hard part -- now you can specify exact time value using Decimal or Fraction.
pythongh-67795: Improve precision of non-float timestamp and timeout …
gh-67795: Improve precision of non-float timestamp and timeout argume…
encukou commentedon Nov 30, 2026
Since the PR was merged, buildbots fail on ARM Raspbian and x86 Debian.
gh-67795: Skip test values below the time_t minimum on platforms with…
pythongh-67795: Refactor pytime.c code handling double
pythongh-67795: Remove _PyTime_FromSecondsDouble() function
gh-67795: Remove _PyTime_FromSecondsDouble() function (#162906)
pythongh-67795: Add pytime_double_to_time_t() helper function
gh-67795: Add pytime_double_to_time_t() helper function (#162904)