diff --git a/pgactivity/config.py b/pgactivity/config.py index dde6d66b..280b93fa 100644 --- a/pgactivity/config.py +++ b/pgactivity/config.py @@ -174,11 +174,17 @@ def from_config_section(cls: Type[_T], section: configparser.SectionProxy) -> _T unknown_options = set(section) - set(known_options) if unknown_options: raise ValueError(f"invalid option(s): {', '.join(sorted(unknown_options))}") - for opt, getter in (("hidden", section.getboolean), ("width", section.getint)): - try: - values[opt] = getter(opt) - except configparser.NoOptionError: - pass + try: + hidden = section.getboolean("hidden") + except configparser.NoOptionError: + pass + else: + if hidden is not None: + values["hidden"] = hidden + try: + values["width"] = section.getint("width") + except configparser.NoOptionError: + pass return cls(**values) diff --git a/tests/test_config.py b/tests/test_config.py index e3b890bd..93909b88 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -83,4 +83,4 @@ def asdict(cfg: Configuration) -> Dict[str, Any]: (tmp_path / "pg_activity.conf").write_text("\n".join(["[client]", "width=5"])) cfg = Configuration.lookup(user_config_home=tmp_path) - assert cfg is not None and asdict(cfg) == {"client": {"hidden": None, "width": 5}} + assert cfg is not None and asdict(cfg) == {"client": {"hidden": False, "width": 5}}