Skip to content

Commit

Permalink
Only use keyword arguments for HBARecord constructor
Browse files Browse the repository at this point in the history
The values argument wasn't really useful.

It also makes Mypy happy with the following syntax:
HBARecord(**a_mapping)

The previous required syntax was:
HBARecord(values=a_mapping)
  • Loading branch information
pgiraud committed Dec 11, 2024
1 parent 2bbea14 commit fc5fbac
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions pgtoolkit/hba.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
import re
import sys
import warnings
from collections.abc import Callable, Iterable, Iterator, Sequence
from collections.abc import Callable, Iterable, Iterator
from pathlib import Path
from typing import IO, Any

Expand Down Expand Up @@ -164,27 +164,19 @@ def parse(cls, line: str) -> HBARecord:
# Remove extra outer double quotes for auth options values if any
auth_options = [(o[0], re.sub(r"^\"|\"$", "", o[1])) for o in auth_options]
options = base_options + auth_options
return cls(options, comment=comment)
return cls(**{k: v for k, v in options}, comment=comment)

conntype: str | None
database: str
user: str

def __init__(
self,
values: Iterable[tuple[str, str]] | dict[str, Any] | None = None,
comment: str | None = None,
**kw_values: str | Sequence[str],
) -> None:
def __init__(self, *, comment: str | None = None, **values: Any) -> None:
"""
:param values: A dict of fields.
:param kw_values: Fields passed as keyword.
:param comment: Comment at the end of the line.
:param values: Fields passed as keyword.
"""
dict_values: dict[str, Any] = dict(values or {}, **kw_values)
self.__dict__.update(dict_values)
self.fields = [k for k, _ in dict_values.items()]
self.comment = comment
self.__dict__.update(values)
self.fields = list(values)

def __repr__(self) -> str:
return "<{} {}{}>".format(
Expand Down

0 comments on commit fc5fbac

Please sign in to comment.