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

Improve message of PyType_Spec deprecation warning with location #107810

Closed
cdce8p opened this issue Aug 9, 2023 · 3 comments
Closed

Improve message of PyType_Spec deprecation warning with location #107810

cdce8p opened this issue Aug 9, 2023 · 3 comments
Labels
triaged The issue has been accepted as valid by a triager. type-feature A feature request or enhancement

Comments

@cdce8p
Copy link
Contributor

cdce8p commented Aug 9, 2023

Bug report

A clear and concise description of the bug

Followup to #103968 (comment).
The DeprecationWarning for PyType_Spec in 3.12.0rc1 is emitted on <frozen importlib._bootstrap>:400 which makes it quite difficult to know what package is responsible.

In my particular case I found that, after reading #103968, it might be protobuf.
And indeed that's how I can reproduce it.

# test.py
from google.protobuf import descriptor
pip install protobuf==4.24.0
python -X dev test.py
<frozen importlib._bootstrap>:400
    DeprecationWarning: Using PyType_Spec with metaclasses that have custom tp_new is deprecated and will no longer be allowed in Python 3.14.

To be clear, I don't mind the warning. I'm just wondering if it's possible to improve the error location.
/CC @encukou

--
The relevant CPython code

cpython/Objects/typeobject.c

Lines 4243 to 4249 in 3bb43b7

if (PyErr_WarnFormat(
PyExc_DeprecationWarning, 1,
"Using PyType_Spec with metaclasses that have custom "
"tp_new is deprecated and will no longer be allowed in "
"Python 3.14.") < 0) {
goto finally;
}

And protobuf where it's likely (?) created:
https://github.com/protocolbuffers/protobuf/blob/v4.24.0/python/google/protobuf/pyext/map_container.cc#L562
https://github.com/protocolbuffers/protobuf/blob/v4.24.0/python/google/protobuf/pyext/map_container.cc#L778

Your environment

  • CPython versions tested on: 3.12.0rc1 and with the latest 3.12 commit: 3bb43b7
  • Operating system and architecture: MacOS

Linked PRs

@cdce8p cdce8p added the type-bug An unexpected behavior, bug, or error label Aug 9, 2023
@Eclips4
Copy link
Member

Eclips4 commented Aug 9, 2023

At this moment we have access to spec->name. So, we can improve warning message:

            if (PyErr_WarnFormat(
                    PyExc_DeprecationWarning, 1,
                    "Type %s uses PyType_Spec with metaclasses that have custom ",
                    "tp_new is deprecated and will no longer be allowed in "
                    "Python 3.14.", spec->name) < 0) {
                goto finally;

Does it enough?

@Eclips4
Copy link
Member

Eclips4 commented Aug 9, 2023

Also, I don't think it's a bug. It's looks like an enhancement ;)

@Eclips4 Eclips4 added type-feature A feature request or enhancement and removed type-bug An unexpected behavior, bug, or error labels Aug 9, 2023
@Eclips4 Eclips4 changed the title PyType_Spec deprecation warning location Improve message of PyType_Spec deprecation warning with location Aug 9, 2023
@Eclips4 Eclips4 added the triaged The issue has been accepted as valid by a triager. label Aug 9, 2023
encukou pushed a commit that referenced this issue Aug 10, 2023
…new (GH-107834)


Co-authored-by: Kirill Podoprigora <kirill.bast9@mail.ru>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Aug 11, 2023
…om tp_new (pythonGH-107834)

(cherry picked from commit 16dcce2)

Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
Co-authored-by: Kirill Podoprigora <kirill.bast9@mail.ru>
Yhg1s pushed a commit that referenced this issue Aug 11, 2023
…tom tp_new (GH-107834) (#107864)

gh-107810: Improve DeprecationWarning for metaclasses with custom tp_new (GH-107834)

(cherry picked from commit 16dcce2)

Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
Co-authored-by: Kirill Podoprigora <kirill.bast9@mail.ru>
@cdce8p
Copy link
Contributor Author

cdce8p commented Aug 11, 2023

Thanks everyone who contributed. The change has been merged into main and 3.12 now. Closing this as completed.

@cdce8p cdce8p closed this as completed Aug 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triaged The issue has been accepted as valid by a triager. type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

2 participants