-
Notifications
You must be signed in to change notification settings - Fork 651
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
Handle traceback.format_exception() API change in Python 3.10 #2018
Handle traceback.format_exception() API change in Python 3.10 #2018
Conversation
The first argument of traceback.format_exception() has been renamed from “etype” to “exc” and is now positional-only. Passing it as a positional argument rather than a keyword argument fixes a TypeError on Python 3.10 while remaining compatible with previous Python releases: • On Python 3.10, the parameter *should* be the exception object; it is now possible to call format_exception() with only the exception object, omitting “value” and “tb”. Here the type of the exception object is given instead; however, this is OK because “value” and “tb” are also given, and therefore the positional “exc” parameter is ignored and may have any value or type whatsoever. • From Python 3.5 to 3.9, the first argument is “etype” and is correctly the type of the exception object; however, its actual value is still ignored in favor of the type of “value”. • Prior to Python 3.5, the “etype” would actually be used, if this project supported those Python versions. The changes in the traceback module in Python 3.10 are documented at: https://docs.python.org/3.10/library/traceback.html#traceback.print_exception https://docs.python.org/3.10/library/traceback.html#traceback.format_exception https://docs.python.org/3.10/library/traceback.html#traceback.format_exception_only https://docs.python.org/3.10/library/traceback.html#traceback.TracebackException.format_exception_only
Is this a fix for #1975? |
No, I don’t currently have a fix for #1975, which affects the Instead, this PR fixes an unrelated test failure in |
Can we add 3.10 to the CI? I am wondering if it is possible since final release 3.10 yet to be done. |
The first argument of
traceback.format_exception()
has been renamed from “etype
” to “exc
” and is now positional-only. Passing it as a positional argument rather than a keyword argument fixes aTypeError
on Python 3.10 while remaining compatible with previous Python releases:format_exception()
with only the exception object, omitting “value
” and “tb
”. Here the type of the exception object is given instead; however, this is OK because “value
” and “tb
” are also given, and therefore the positional “exc
” parameter is ignored and may have any value or type whatsoever.etype
” and is correctly the type of the exception object; however, its actual value is still ignored in favor of the type of “value
”.etype
” would actually be used, if this project supported those Python versions.The changes in the
traceback
module in Python 3.10 are documented at:https://docs.python.org/3.10/library/traceback.html#traceback.print_exception
https://docs.python.org/3.10/library/traceback.html#traceback.format_exception
https://docs.python.org/3.10/library/traceback.html#traceback.format_exception_only
https://docs.python.org/3.10/library/traceback.html#traceback.TracebackException.format_exception_only
Description
See the formatted commit message text above.
Fixes # (issue)
No issue has been filed.
Type of change
How Has This Been Tested?
I’m working on updating the
python-opentelemetry
package on Fedora Linux, which I just started maintaining. I can confirm this fixes failingopentelemetry-opentracing-shim
tests on Fedora Rawhide (the development version) with a pre-release version of Python 3.10. The updated package isn’t yet ready, but fortunately you don’t need to use the same environment as I am to replicate this.Suffice it to say that if you try to run the tests on Python 3.10 in any environment, you should see a
TypeError
in theopentelemetry-opentracing-shim
tests, and you should find that this PR fixes it. Furthermore, you can confirm compatibility with Python 3.9 and older by running the tests however you normally run them. Nothing about this PR is sensitive to the particulars of your environment other than the Python version.Does This PR Require a Contrib Repo Change?
Answer the following question based on these examples of changes that would require a Contrib Repo Change:
The OTel specification has changed which prompted this PR to update the method interfaces of
opentelemetry-api/
oropentelemetry-sdk/
The method interfaces of
opentelemetry-instrumentation/
have changedThe method interfaces of
test/util
have changedScripts in
scripts/
that were copied over to the Contrib repo have changedConfiguration files that were copied over to the Contrib repo have changed (when consistency between repositories is applicable) such as in
pyproject.toml
isort.cfg
.flake8
When a new
.github/CODEOWNER
is addedMajor changes to project information, such as in:
README.md
CONTRIBUTING.md
Yes. - Link to PR:
No.
Checklist: