pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/python/cpython/pull/122156/files

dia="all" rel="stylesheet" href="https://github.githubassets.com/assets/code-2d31826944fd3be8.css" /> [3.13] gh-122088: Copy the coroutine status of the underlying callable in `@warnings.deprecated` (GH-122086) by miss-islington · Pull Request #122156 · python/cpython · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions Lib/test/test_warnings/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from contextlib import contextmanager
import linecache
import os
import inspect
from io import StringIO
import re
import sys
Expand Down Expand Up @@ -1682,6 +1683,29 @@ def d(): pass
isinstance(cell.cell_contents, deprecated) for cell in d.__closure__
))

def test_inspect(self):
@deprecated("depr")
def sync():
pass

@deprecated("depr")
async def coro():
pass

class Cls:
@deprecated("depr")
def sync(self):
pass

@deprecated("depr")
async def coro(self):
pass

self.assertFalse(inspect.iscoroutinefunction(sync))
self.assertTrue(inspect.iscoroutinefunction(coro))
self.assertFalse(inspect.iscoroutinefunction(Cls.sync))
self.assertTrue(inspect.iscoroutinefunction(Cls.coro))

def setUpModule():
py_warnings.onceregistry.clear()
c_warnings.onceregistry.clear()
Expand Down
4 changes: 4 additions & 0 deletions Lib/warnings.py
Original file line number Diff line number Diff line change
Expand Up @@ -629,12 +629,16 @@ def __init_subclass__(*args, **kwargs):
return arg
elif callable(arg):
import functools
import inspect

@functools.wraps(arg)
def wrapper(*args, **kwargs):
warn(msg, category=category, stacklevel=stacklevel + 1)
return arg(*args, **kwargs)

if inspect.iscoroutinefunction(arg):
wrapper = inspect.markcoroutinefunction(wrapper)

arg.__deprecated__ = wrapper.__deprecated__ = msg
return wrapper
else:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
:func:`@warnings.deprecated <warnings.deprecated>` now copies the
coroutine status of functions and methods so that
:func:`inspect.iscoroutinefunction` returns the correct result.
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy