Skip to content
Closed
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
4 changes: 3 additions & 1 deletion src/h2/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 6 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down