Handle traceback.format_exception() API change in Python 3.10#2018
Merged
lzchen merged 5 commits intoopen-telemetry:mainfrom Aug 16, 2021
Merged
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
Contributor
|
Is this a fix for #1975? |
Contributor
Author
No, I don’t currently have a fix for #1975, which affects the Instead, this PR fixes an unrelated test failure in |
srikanthccv
approved these changes
Aug 13, 2021
Member
|
Can we add 3.10 to the CI? I am wondering if it is possible since final release 3.10 yet to be done. |
ocelotl
approved these changes
Aug 13, 2021
lzchen
approved these changes
Aug 16, 2021
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 aTypeErroron 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
tracebackmodule 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-opentelemetrypackage on Fedora Linux, which I just started maintaining. I can confirm this fixes failingopentelemetry-opentracing-shimtests 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
TypeErrorin theopentelemetry-opentracing-shimtests, 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/utilhave 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.tomlisort.cfg.flake8When a new
.github/CODEOWNERis addedMajor changes to project information, such as in:
README.mdCONTRIBUTING.mdYes. - Link to PR:
No.
Checklist: