From 019fd527c2ac2c8592a01613c33613321cada5fa Mon Sep 17 00:00:00 2001 From: Min RK Date: Fri, 17 Jun 2022 11:22:53 +0200 Subject: [PATCH] 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 --- tornado/ioloop.py | 6 +++++- tornado/platform/asyncio.py | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) 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: -- 2.47.2