Skip to content

Incompatibility between _decimal and _pydecimal: tp_name for Decimal #119299

Description

@skirpichev

Bug report

Bug description:

For the _decimal module we have Decimal's tp_name set to "decimal.Decimal", while for the _pydecimal version it's just "Decimal". Same is true for other provided types. Not sure that this affects many projects (from pure-python side I don't see differences due to this setting). But here is a bugfix from gmpy2: gmpy2/gmpy2@4a05610

Maybe it worth to make these slots identical? I doubt there is a way to change pure-Python version to C-version, but it's easy to do the opposite:

diff --git a/Modules/_decimal/_decimal.c b/Modules/_decimal/_decimal.c
index 2daa24c823..2d58e51fa3 100644
--- a/Modules/_decimal/_decimal.c
+++ b/Modules/_decimal/_decimal.c
@@ -5068,7 +5068,7 @@ static PyType_Slot dec_slots[] = {
 
 
 static PyType_Spec dec_spec = {
-    .name = "decimal.Decimal",
+    .name = "Decimal",
     .basicsize = sizeof(PyDecObject),
     .flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE |
               Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_IMMUTABLETYPE),

As before, I don't see that this affects pure-Python code, using the decimal module. Both __name__ and __module__ attributes are correct:

>>> import _decimal
>>> import _pydecimal
>>> _decimal.Decimal.__module__
'decimal'
>>> _pydecimal.Decimal.__module__
'decimal'
>>> _pydecimal.Decimal.__name__
'Decimal'
>>> _decimal.Decimal.__name__
'Decimal'

CPython versions tested on:

CPython main branch

Operating systems tested on:

No response

Activity

  1. added
    stdlibStandard Library Python modules in the Lib/ directory
    on May 21, 2024
  2. self-assigned this
    on Apr 16, 2025
  3. removed their assignment
    on Apr 19, 2025
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 dirstdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions