From a8aea09190d0e06db906cdc5eb924fd5bf1fedff Mon Sep 17 00:00:00 2001 From: leycec Date: Mon, 23 Sep 2024 00:08:25 -0400 Subject: [PATCH] Significant cleanup x 15. This commit is the next in a commit chain quietly resurrecting BETSE for a modern audience and the modern Python ecosystem. Specifically, this commit continues resolving failing GitHub Actions-based continuous integration (CI) workflows. BETSE 1.4.0 is now still days from official release, supposedly. (*Despised reprisals!*) --- betse/util/io/error/errwarning.py | 9 +++------ betse/util/type/typehints.py | 8 ++++++++ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/betse/util/io/error/errwarning.py b/betse/util/io/error/errwarning.py index 4c3e5973..c059b642 100644 --- a/betse/util/io/error/errwarning.py +++ b/betse/util/io/error/errwarning.py @@ -10,12 +10,9 @@ # ....................{ IMPORTS }.................... import sys, warnings -from beartype.typing import ( - ContextManager, - Generator, -) from betse.util.io.log import logs from betse.util.type.types import ClassType +from betse.util.type.typehints import ContextManagerOrGenerator from contextlib import contextmanager # ....................{ INITIALIZERS }.................... @@ -82,7 +79,7 @@ def init() -> None: logs.log_debug('Deferring to default warning policy.') # ....................{ MANAGERS }.................... -def ignoring_deprecations() -> ContextManager: +def ignoring_deprecations() -> ContextManagerOrGenerator: ''' Single-shot context manager temporarily ignoring all **deprecation warnings** (i.e., instances of the :class:`DeprecationWarning`, @@ -104,7 +101,7 @@ def ignoring_deprecations() -> ContextManager: @contextmanager -def ignoring_warnings(*warning_clses: ClassType) -> Generator: +def ignoring_warnings(*warning_clses: ClassType) -> ContextManagerOrGenerator: ''' Single-shot context manager temporarily ignoring *all* warnings of *all* passed warning types emitted by the :mod:`warnings` module for the duration diff --git a/betse/util/type/typehints.py b/betse/util/type/typehints.py index c9b92a3e..28ba3a6f 100644 --- a/betse/util/type/typehints.py +++ b/betse/util/type/typehints.py @@ -11,6 +11,8 @@ # ....................{ IMPORTS }.................... from beartype.typing import ( Annotated, + ContextManager, + Generator, ) from beartype.vale import ( IsAttr, @@ -18,6 +20,12 @@ ) from numpy import ndarray +# ....................{ HINTS }.................... +ContextManagerOrGenerator = ContextManager | Generator +''' +PEP-compliant type hint matching either a context manager *or* generator. +''' + # ....................{ HINTS ~ lib : numpy : 1d }.................... NDArrayNdim1 = Annotated[ndarray, IsAttr['ndim', IsEqual[1]]] '''