Skip to content

Useless code block in math.trunc() ? #111417

Description

@skirpichev

Bug report

Bug description:

The math.trunc function has:

cpython/Modules/mathmodule.c

Lines 2073 to 2076 in f013b47

if (!_PyType_IsReady(Py_TYPE(x))) {
if (PyType_Ready(Py_TYPE(x)) < 0)
return NULL;
}

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

Activity

  1. added a commit that references this issue on Oct 29, 2023
  2. Jason-Y-Z commented on Oct 29, 2023

    @Jason-Y-Z
    Contributor

    Created a small PR to remove the unused code block - #111454

  3. serhiy-storchaka commented on Nov 7, 2023

    @serhiy-storchaka
    Member

    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, calls find_name_in_mro() which looks up tp_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() and PyType_Ready() look more justified.

  4. skirpichev commented on Nov 8, 2023

    @skirpichev
    MemberAuthor

    @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.

  5. added a commit that references this issue on Feb 3, 2024
  6. added a commit that references this issue on Feb 3, 2024
  7. added a commit that references this issue on Feb 11, 2024
  8. added a commit that references this issue on Feb 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    extension-modulesC modules in the Modules dirtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions