Skip to content

Incompatibility between _decimal and _pydecimal: tp_name for Decimal #119299

@skirpichev

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: aleaxit/gmpy@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

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions