Repository navigation
Useless code block in math.trunc() ? #111417
Description
Activity
- addedtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
on Oct 28, 2023 - added a commit that references this issue
on Oct 29, 2023 Created a small PR to remove the unused code block - #111454
I suggested @skirpichev to open a separate issue for discussion and reference. Previously this change was hidden in a pile of unrelated changes.
Now I think that it is safe. This check is immediately followed by
_PyObject_LookupSpecial()which calls_PyType_Lookup()which, after looking in the type cache, callsfind_name_in_mro()which looks uptp_mro, and, if it has not yet been set, make the type ready.I think that a similar code in the builtin
round()can be removed as well. Other uses of_PyType_IsReady()andPyType_Ready()look more justified.@serhiy-storchaka, in the end, it was your commit, that makes additional
PyType_Ready()(since 15d3d04) call here useless: 8ef3460.@Jason-Y-Z, I think you could reference that commit in you commit message. And remove similar code in
round(), of course.- addedextension-modulesC modules in the Modules dirC modules in the Modules dir
on Nov 26, 2023
Bug report
Bug description:
The math.trunc function has:
cpython/Modules/mathmodule.c
Lines 2073 to 2076 in f013b47
c.f. math.ceil or math.floor.
This seems to be a history artifact: the function was introduced in 400adb0 as a moved builtins.trunc(), while math.ceil/floor were here from the initial revision.
I think it's safe to remove mentioned block.
PS: Issue opened per @serhiy-storchaka suggestion in #110000.
CPython versions tested on:
CPython main branch
Operating systems tested on:
No response
Linked PRs