diff --git a/src/h2/config.py b/src/h2/config.py index cbc3b1eaa..aab4d8653 100644 --- a/src/h2/config.py +++ b/src/h2/config.py @@ -20,7 +20,9 @@ def __init__(self, name: str) -> None: self.name = name self.attr_name = f"_{self.name}" - def __get__(self, instance: Any, owner: Any) -> bool: + def __get__(self, instance: Any, owner: Any) -> bool | _BooleanConfigOption: + if instance is None: + return self return getattr(instance, self.attr_name) # type: ignore def __set__(self, instance: Any, value: bool) -> None: diff --git a/tests/test_config.py b/tests/test_config.py index 5651f7bab..03817fe8c 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -32,6 +32,12 @@ def test_defaults(self) -> None: "normalize_inbound_headers", ] + @pytest.mark.parametrize("option_name", boolean_config_options) + def test_boolean_config_options_expose_descriptor_on_class(self, option_name) -> None: + """Boolean config options return their descriptor on class access.""" + descriptor = h2.config.H2Configuration.__dict__[option_name] + assert getattr(h2.config.H2Configuration, option_name) is descriptor + @pytest.mark.parametrize("option_name", boolean_config_options) @pytest.mark.parametrize("value", [None, "False", 1]) def test_boolean_config_options_reject_non_bools_init(