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

[MISC] Switch to Ruff #130

Merged
merged 3 commits into from
Aug 22, 2023
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: 1 addition & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ on:
- renovate.json
- poetry.lock
- pyproject.toml
- '.github/workflows/ci.yaml'

jobs:
ci-tests:
Expand Down
26 changes: 14 additions & 12 deletions lib/charms/pgbouncer_k8s/v0/pgb.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
LIBAPI = 0
# Increment this PATCH version before using `charmcraft publish-lib` or reset
# to 0 if you are raising the major API version
LIBPATCH = 7
LIBPATCH = 8

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -134,6 +134,8 @@ def __init__(
Args:
config: an existing config. Can be passed in as a string, dict, or PgbConfig object.
pgb.DEFAULT_CONFIG can be used here as a default dict.
args: arguments.
kwargs: keyword arguments.
"""
self.__dict__.update(*args, **kwargs)

Expand Down Expand Up @@ -180,29 +182,29 @@ def items(self):
"""Returns items of PgbConfig object."""
return self.__dict__.items()

def read_dict(self, input: Dict) -> None:
def read_dict(self, data: Dict) -> None:
"""Populates this object from a dictionary.
Args:
input: Dict to be read into this object. This dict must follow the pgbouncer config
spec (https://pgbouncer.org/config.html) to pass validation, implementing each
section as its own subdict. Lists should be represented as python lists, not
comma-separated strings.
data: Dict to be read into this object. This dict must follow the pgbouncer config
spec (https://pgbouncer.org/config.html) to pass validation, implementing each
section as its own subdict. Lists should be represented as python lists, not
comma-separated strings.
"""
self.update(deepcopy(input))
self.update(deepcopy(data))
self.validate()

def read_string(self, input: str) -> None:
def read_string(self, data: str) -> None:
"""Populates this class from a pgbouncer.ini file, passed in as a string.
Args:
input: pgbouncer.ini file to be parsed, represented as a string. This string must
follow the pgbouncer config spec (https://pgbouncer.org/config.html)
data: pgbouncer.ini file to be parsed, represented as a string. This string must
follow the pgbouncer config spec (https://pgbouncer.org/config.html)
"""
# Since the parser persists data across reads, we have to create a new one for every read.
parser = ConfigParser()
parser.optionxform = str
parser.read_string(input)
parser.read_string(data)

self.update(deepcopy(dict(parser)))
# Convert Section objects to dictionaries, so they can hold dictionaries themselves.
Expand Down Expand Up @@ -235,7 +237,7 @@ def _parse_complex_variables(self) -> None:
except KeyError as err:
raise PgbConfig.ConfigParsingError(source=str(err))

for name, cfg_string in self.get(users, dict()).items():
for name, cfg_string in self.get(users, {}).items():
self[users][name] = parse_kv_string_to_dict(cfg_string)

for user_type in PgbConfig.user_types:
Expand Down
Loading