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
1 change: 0 additions & 1 deletion conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import platform


not_macOS = platform.system() != 'Darwin'

collect_ignore = ["hook-keyring.backend.py"] + [
Expand Down
18 changes: 10 additions & 8 deletions keyring/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
Core API functions and initialization routines.
"""

from __future__ import annotations

import configparser
import logging
import os
Expand Down Expand Up @@ -58,7 +60,7 @@ def disable() -> None:
file.write('[backend]\ndefault-keyring=keyring.backends.null.Keyring')


def get_password(service_name: str, username: str) -> typing.Optional[str]:
def get_password(service_name: str, username: str) -> str | None:
"""Get password from the specified service."""
return get_keyring().get_password(service_name, username)

Expand All @@ -74,8 +76,8 @@ def delete_password(service_name: str, username: str) -> None:


def get_credential(
service_name: str, username: typing.Optional[str]
) -> typing.Optional[credentials.Credential]:
service_name: str, username: str | None
) -> credentials.Credential | None:
"""Get a Credential for the specified service."""
return get_keyring().get_credential(service_name, username)

Expand All @@ -84,14 +86,14 @@ def recommended(backend) -> bool:
return backend.priority >= 1


def init_backend(limit: typing.Optional[LimitCallable] = None):
def init_backend(limit: LimitCallable | None = None):
"""
Load a detected backend.
"""
set_keyring(_detect_backend(limit))


def _detect_backend(limit: typing.Optional[LimitCallable] = None):
def _detect_backend(limit: LimitCallable | None = None):
"""
Return a keyring specified in the config file or infer the best available.

Expand All @@ -113,7 +115,7 @@ def _detect_backend(limit: typing.Optional[LimitCallable] = None):
)


def _load_keyring_class(keyring_name: str) -> typing.Type[backend.KeyringBackend]:
def _load_keyring_class(keyring_name: str) -> type[backend.KeyringBackend]:
"""
Load the keyring class indicated by name.

Expand Down Expand Up @@ -145,7 +147,7 @@ def load_keyring(keyring_name: str) -> backend.KeyringBackend:
return class_()


def load_env() -> typing.Optional[backend.KeyringBackend]:
def load_env() -> backend.KeyringBackend | None:
"""Load a keyring configured in the environment variable."""
try:
return load_keyring(os.environ['PYTHON_KEYRING_BACKEND'])
Expand All @@ -163,7 +165,7 @@ def _ensure_path(path):
return path


def load_config() -> typing.Optional[backend.KeyringBackend]:
def load_config() -> backend.KeyringBackend | None:
"""Load a keyring using the config file in the config root."""

config = configparser.RawConfigParser()
Expand Down
3 changes: 1 addition & 2 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@

import pytest

from keyring import cli
from keyring import credentials
from keyring import cli, credentials

flatten = itertools.chain.from_iterable

Expand Down