Skip to content

Commit

Permalink
twisted#12026 Suppress a deprecation warning on Python 3.12
Browse files Browse the repository at this point in the history
The three-arg form of generator.throw() was deprecated in Python
3.12. However, we're not sure if the modern one-arg form works
on Python 3.8, which is still supported, so instead of changing
it right now, this just suppresses the warning.

Signed-off-by: Adam Williamson <awilliam@redhat.com>
  • Loading branch information
AdamWill committed Oct 28, 2023
1 parent 157cd8e commit 844b9e2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/twisted/newsfragments/12026.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Suppress a deprecation warning on Python 3.12
8 changes: 7 additions & 1 deletion src/twisted/python/failure.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import inspect
import linecache
import sys
import warnings
from inspect import getmro
from io import StringIO
from typing import Callable, NoReturn, TypeVar
Expand Down Expand Up @@ -516,7 +517,12 @@ def throwExceptionIntoGenerator(self, g):
"""
# Note that the actual magic to find the traceback information
# is done in _findFailure.
return g.throw(self.type, self.value, self.tb)
with warnings.catch_warnings():
# three-arg form is deprecated in Python 3.12, but one-arg
# form was only introduced in 3.9, so filter the warning
# until 3.9 is EOL
warnings.simplefilter("ignore")
return g.throw(self.type, self.value, self.tb)

@classmethod
def _findFailure(cls):
Expand Down

0 comments on commit 844b9e2

Please sign in to comment.