commit: 1b50ee17d387b54a102c91eff405ce2d183d6fbd
Author: Brian Harring <ferringb <AT> gmail <DOT> com>
AuthorDate: Wed Dec 17 12:29:37 2025 +0000
Commit: Brian Harring <ferringb <AT> gmail <DOT> com>
CommitDate: Wed Dec 17 12:29:37 2025 +0000
URL:
https://gitweb.gentoo.org/proj/pkgcore/snakeoil.git/commit/?id=1b50ee17
Allow deprecations.suppress_deprecations to *not* suppress warnings w/in
generators.
Pkgcore's repo.itermatch will be marked deprecated- however both for visibility
and
performance, we will *not* want it suppressing deprecations within.
Thus make this configurable. I'm not sure it'll actually be used there, but
I suspect in downstream consumers of this API- as it's extended into that code-
this will be a necessary edgecase configurable.
Signed-off-by: Brian Harring <ferringb <AT> gmail.com>
src/snakeoil/deprecation/__init__.py | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/src/snakeoil/deprecation/__init__.py
b/src/snakeoil/deprecation/__init__.py
index 5feae6e..e5bdee0 100644
--- a/src/snakeoil/deprecation/__init__.py
+++ b/src/snakeoil/deprecation/__init__.py
@@ -70,13 +70,15 @@ class suppress_deprecations:
__slots__ = (
"_warning_ctx",
"kwargs",
+ "wraps_generators",
)
_warnings_ctx: None | warnings.catch_warnings
- def __init__(self, category=DeprecationWarning, **kwargs):
+ def __init__(self, category=DeprecationWarning, wrap_generators=True,
**kwargs):
kwargs.setdefault("action", "ignore")
kwargs.setdefault("category", DeprecationWarning)
self.kwargs = kwargs
+ self.wraps_generators = wrap_generators
self._warning_ctx = None
def __enter__(self):
@@ -100,7 +102,7 @@ class suppress_deprecations:
# instantiate a new instance. The callable may result in
re-entrancy.
with (ctx := self.__class__(**self.kwargs)):
result = thing(*args, **kwargs)
- if inspect.isgenerator(result):
+ if inspect.isgenerator(result) and self.wraps_generators:
return _GeneratorProxy(result, ctx) # pyright:
ignore[reportReturnType]
return result