Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incompatibility between _decimal and _pydecimal: tp_name for Decimal #119299

Open
skirpichev opened this issue May 21, 2024 · 0 comments
Open

Incompatibility between _decimal and _pydecimal: tp_name for Decimal #119299

skirpichev opened this issue May 21, 2024 · 0 comments
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@skirpichev
Copy link
Contributor

skirpichev commented May 21, 2024

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

@skirpichev skirpichev added the type-bug An unexpected behavior, bug, or error label May 21, 2024
@aisk aisk added the stdlib Python modules in the Lib dir label May 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
2 participants