Skip to content

Commit 350c898

Browse files
committed
Only use keyword arguments for HBARecord constructor
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)
1 parent 2bbea14 commit 350c898

File tree

1 file changed

+7
-15
lines changed

1 file changed

+7
-15
lines changed

pgtoolkit/hba.py

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
import re
7474
import sys
7575
import warnings
76-
from collections.abc import Callable, Iterable, Iterator, Sequence
76+
from collections.abc import Callable, Iterable, Iterator
7777
from pathlib import Path
7878
from typing import IO, Any
7979

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

169169
conntype: str | None
170170
database: str
171171
user: str
172172

173-
def __init__(
174-
self,
175-
values: Iterable[tuple[str, str]] | dict[str, Any] | None = None,
176-
comment: str | None = None,
177-
**kw_values: str | Sequence[str],
178-
) -> None:
173+
def __init__(self, **values: Any) -> None:
179174
"""
180-
:param values: A dict of fields.
181-
:param kw_values: Fields passed as keyword.
182-
:param comment: Comment at the end of the line.
175+
:param values: Fields passed as keyword.
183176
"""
184-
dict_values: dict[str, Any] = dict(values or {}, **kw_values)
185-
self.__dict__.update(dict_values)
186-
self.fields = [k for k, _ in dict_values.items()]
187-
self.comment = comment
177+
self.__dict__.update(values)
178+
self.comment = values.pop("comment", None)
179+
self.fields = values.keys()
188180

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

0 commit comments

Comments
 (0)