Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

re-use ExceptionTrap from jaraco.context #672

Merged
merged 1 commit into from
Apr 2, 2024
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
9 changes: 6 additions & 3 deletions keyring/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import os
import typing

from jaraco.context import ExceptionTrap
from jaraco.functools import once

from . import credentials, errors, util
Expand Down Expand Up @@ -65,11 +66,13 @@ def priority(self) -> float:
"""
raise NotImplementedError

# Python 3.8 compatibility
passes = ExceptionTrap().passes

@properties.classproperty
@passes
def viable(cls):
with errors.ExceptionRaisedContext() as exc:
cls.priority # noqa: B018
return not exc
cls.priority # noqa: B018

@classmethod
def get_viable_backends(
Expand Down
5 changes: 3 additions & 2 deletions keyring/backends/SecretService.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import logging
from contextlib import closing

from jaraco.context import ExceptionTrap

from .. import backend
from ..backend import KeyringBackend
from ..compat import properties
from ..credentials import SimpleCredential
from ..errors import (
ExceptionRaisedContext,
InitError,
KeyringLocked,
PasswordDeleteError,
Expand All @@ -31,7 +32,7 @@ class Keyring(backend.SchemeSelectable, KeyringBackend):

@properties.classproperty
def priority(cls) -> float:
with ExceptionRaisedContext() as exc:
with ExceptionTrap() as exc:
secretstorage.__name__ # noqa: B018
if exc:
raise RuntimeError("SecretStorage required")
Expand Down
6 changes: 4 additions & 2 deletions keyring/backends/Windows.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import logging

from jaraco.context import ExceptionTrap

from ..backend import KeyringBackend
from ..compat import properties
from ..credentials import SimpleCredential
from ..errors import ExceptionRaisedContext, PasswordDeleteError
from ..errors import PasswordDeleteError

with ExceptionRaisedContext() as missing_deps:
with ExceptionTrap() as missing_deps:
try:
# prefer pywin32-ctypes
from win32ctypes.pywin32 import pywintypes, win32cred
Expand Down
6 changes: 6 additions & 0 deletions keyring/errors.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import sys
import warnings


class KeyringError(Exception):
Expand Down Expand Up @@ -32,6 +33,11 @@ class ExceptionRaisedContext:
"""

def __init__(self, ExpectedException=Exception):
warnings.warn(
"ExceptionRaisedContext is deprecated; use `jaraco.context.ExceptionTrap`",
DeprecationWarning,
stacklevel=2,
)
self.ExpectedException = ExpectedException
self.exc_info = None

Expand Down
1 change: 1 addition & 0 deletions newsfragments/+9aa71ff2.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Replace ExceptionRaisedContext with ExceptionTrap.
Loading