From: Min RK Date: Fri, 17 Jun 2022 09:22:53 +0000 (+0200) Subject: Add stacklevel to deprecation warnings X-Git-Tag: v6.2.0b2~4^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F3159%2Fhead;p=thirdparty%2Ftornado.git Add stacklevel to deprecation warnings so warnings are associated with the line where the deprecated methods are called rather than the line where the warning itself is --- diff --git a/tornado/ioloop.py b/tornado/ioloop.py index 9bb977ba1..b907106ef 100644 --- a/tornado/ioloop.py +++ b/tornado/ioloop.py @@ -312,7 +312,11 @@ class IOLoop(Configurable): This method also clears the current `asyncio` event loop. .. deprecated:: 6.2 """ - warnings.warn("clear_current is deprecated", DeprecationWarning) + warnings.warn( + "clear_current is deprecated", + DeprecationWarning, + stacklevel=2, + ) IOLoop._clear_current() @staticmethod diff --git a/tornado/platform/asyncio.py b/tornado/platform/asyncio.py index 58d31ddd8..eed45d068 100644 --- a/tornado/platform/asyncio.py +++ b/tornado/platform/asyncio.py @@ -341,6 +341,7 @@ class AsyncIOLoop(BaseAsyncIOLoop): warnings.warn( "make_current is deprecated; start the event loop first", DeprecationWarning, + stacklevel=2, ) if not self.is_current: try: @@ -425,6 +426,7 @@ class AnyThreadEventLoopPolicy(_BasePolicy): # type: ignore "AnyThreadEventLoopPolicy is deprecated, use asyncio.run " "or asyncio.new_event_loop instead", DeprecationWarning, + stacklevel=2, ) def get_event_loop(self) -> asyncio.AbstractEventLoop: