-
Notifications
You must be signed in to change notification settings - Fork 15.6k
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
Compiled Python extension does not work with Python 3.12 #12186
Comments
It appears that this applies to both the old C++ native extension and the new upb one. |
That |
IMO, the DeprecationWarning is correct, because the behaviour in Python 3.11 is buggy -- though the bug might be harmless in protobuf's case. protobuf uses I believe (but didn't check, compiling/testing What to do? I wish I had a good answer. Or, if you're sure you're not skipping anything important, temporarily set You might want to follow python/cpython#103968 for a bit before implementing my suggestions. |
Thank you both Gregory and Petr From python/cpython#103968 , Petr mentioned:
And as the TypeError has turned into DeprecationWarning in more recent 3.12. We may want to wait until python/cpython#103968 is resolved and have a correct general solution before get rid of the Warning. Please correct me if I was wrong, @encukou |
That's right. I didn't include the ideas from above, one is specific to protobuf (ABCs) and the other is too hacky. But they should work. |
I tried the Py_TYPE(mutable_mapping.get())->tp_new = Py_TYPE(&PyType_Type)->tp_new; But got following error:
Wondering if you can help us with a fixing PR Petr? |
I intend to. Unfortunately I didn't get to it this week. |
I left some thoughts about this in python/cpython#103968 (comment) TL;DR: I don't think we want to actually run We just want to mix in from collections.abc import MutableMapping
class ScalarMapContainer:
# ...
MutableMapping.register(ScalarMapContainer)
# Mixin the methods manually.
ScalarMapContainer.__contains__ = MutableMapping.__contains__
ScalarMapContainer.keys = MutableMapping.keys
ScalarMapContainer.items = MutableMapping.items
ScalarMapContainer.values = MutableMapping.values
# ... |
I've spent some time trying to build protobuf, so I can send a tested PR, but didn't succeed. I can run a Linux container. How do I build and test this code? Preferably with non-system install of Python.
That sounds like a great idea. |
Just to make it easier to find, this is the latest stack trace in 3.12.0:
As @gpshead alluded to, the TypeError did indeed change to DeprecationWarning but still for some reason results in a EDIT - I think there is a misunderstanding somewhere (maybe by me). While there is something about a |
Actually, my issue is when I turn all warnings (including [tool.pytest.ini_options]
filterwarnings = [
"error",# treat all warnings as errors]
] But if I ignore all [tool.pytest.ini_options]
filterwarnings = [
"error", # treat all warnings as errors
"ignore::DeprecationWarning"
] And a more targeted exclusion also works: [tool.pytest.ini_options]
filterwarnings = [
"error", # treat all warnings as errors
"ignore:.*custom tp_new.*in Python 3.14.*:DeprecationWarning",
] |
We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please add a comment. This issue is labeled |
We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please reopen it. This issue was closed and archived because there has been no new activity in the 14 days since the |
…ableMapping instead of inheriting directly. This prevents these from using abc.ABCMeta metaclass to avoid deprecation warning: ``` DeprecationWarning: Type google._upb._message.MessageMapContainer uses PyType_Spec with a metaclass that has custom tp_new. This is deprecated and will no longer be allowed in Python 3.14. ``` Fixes #15077 Fixes #12186 PiperOrigin-RevId: 609782761
…ableMapping instead of inheriting directly. This prevents these from using abc.ABCMeta metaclass to avoid deprecation warning: ``` DeprecationWarning: Type google._upb._message.MessageMapContainer uses PyType_Spec with a metaclass that has custom tp_new. This is deprecated and will no longer be allowed in Python 3.14. ``` Fixes protocolbuffers#15077 Fixes protocolbuffers#12186 PiperOrigin-RevId: 613029479
What version of protobuf and what language are you using?
Version: 3.19.6 – but I searched the source code and verified that the current release (22.1) and
main
should also be affectedLanguage: Python
What operating system (Linux, Windows, ...) and version?
Fedora Linux Rawhide/39, plus experimental Python 3.12: https://copr.fedorainfracloud.org/coprs/g/python/python3.12/
What runtime / compiler are you using (e.g., python version or gcc version)
Python 3.12.0a5, GCC 13.0.1
What did you do?
Steps to reproduce the behavior:
from google.protobuf.pyext import _message
This import occurred in the generated proto bindings in
googleapis-common-protos
; see downstream bug https://bugzilla.redhat.com/show_bug.cgi?id=2176158.What did you expect to see
Successful import with no output.
What did you see instead?
Make sure you include information that can help us debug (full error message, exception listing, stack trace, logs).
Anything else we should know about your project / environment
See python/cpython#93012.
Grepping for
tp_new
inmain
gives:The text was updated successfully, but these errors were encountered: