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

Typing: Add type annotations to config.py #6557

Merged
merged 1 commit into from Mar 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 16 additions & 16 deletions lib/rucio/core/config.py
Expand Up @@ -35,23 +35,23 @@
SECTIONS_CACHE_KEY = 'sections'


def _has_section_cache_key(section):
def _has_section_cache_key(section: str) -> str:
return 'has_section_%s' % section


def _options_cache_key(section):
def _options_cache_key(section: str) -> str:
return 'options_%s' % section


def _has_option_cache_key(section, option):
def _has_option_cache_key(section: str, option: str) -> str:
return 'has_option_%s_%s' % (section, option)


def _items_cache_key(section):
def _items_cache_key(section: str) -> str:
return 'items_%s' % section


def _value_cache_key(section, option):
def _value_cache_key(section: str, option: str) -> str:
return 'get_%s_%s' % (section, option)


Expand All @@ -61,7 +61,7 @@ def sections(
use_cache: bool = True,
expiration_time: int = 900,
session: "Session"
):
) -> list[str]:
"""
Return a list of the sections available.

Expand All @@ -83,7 +83,7 @@ def sections(


@transactional_session
def add_section(section: str, *, session: "Session"):
def add_section(section: str, *, session: "Session") -> None:
"""
Add a section to the configuration.
:param session: The database session in use.
Expand Down Expand Up @@ -151,13 +151,13 @@ def options(

@read_session
def has_option(
section,
option,
section: str,
option: str,
*,
use_cache=True,
expiration_time=900,
use_cache: bool = True,
expiration_time: int = 900,
session: "Session"
):
) -> bool:
"""
Check if the given section exists and contains the given option.

Expand Down Expand Up @@ -260,7 +260,7 @@ def set(
value: Any,
*,
session: "Session"
):
) -> None:
"""
Set the given option to the specified value. If the option doesn't exist, it is created.

Expand Down Expand Up @@ -353,7 +353,7 @@ def remove_option(section: str, option: str, *, session: "Session") -> bool:
return True


def read_from_cache(key, expiration_time=900):
def read_from_cache(key: str, expiration_time: int = 900) -> Any:
"""
Try to read a value from a cache.

Expand All @@ -365,7 +365,7 @@ def read_from_cache(key, expiration_time=900):
return value


def write_to_cache(key, value):
def write_to_cache(key: str, value: Any) -> None:
"""
Set a value on a key in a cache.

Expand All @@ -376,7 +376,7 @@ def write_to_cache(key, value):
REGION.set(key, value)


def delete_from_cache(key):
def delete_from_cache(key: str) -> None:
"""
Delete from cache any data stored for the given key

Expand Down