fix endless loop in redirects

This commit is contained in:
Aran-Fey
2025-02-25 12:05:39 +01:00
parent 16eb01ceb2
commit 79a18ca64e
3 changed files with 31 additions and 9 deletions
+22 -2
View File
@@ -3,12 +3,32 @@ import pytest
import rio
# Sometimes components need a custom `__init__` method, and it's easy to
# overlook mutable default values when you turn the type annotations into
# constructor parameters. This can lead to components sharing state ACROSS
# SESSIONS, which is REALLY REALLY bad. Make sure there are no constructors with
# mutable default arguments.
all_components = list(introspection.get_subclasses(rio.Component))
def is_mutable(value: object) -> bool:
if value is None:
return False
if isinstance(value, (int, float, str, bytes)):
return False
if value == ():
return False
return True
# We have to be careful here not to pick up any Components from test files. It
# makes vscode extremely confused and unable to run the tests.
all_components = [
obj
for obj in vars(rio).values()
if isinstance(obj, type) and issubclass(obj, rio.Component)
]
@pytest.mark.parametrize(
@@ -19,7 +39,7 @@ def test_constructor_has_no_mutable_defaults(cls: type):
params_with_mutable_defaults = [
parameter.name
for parameter in constructor_signature.parameter_list
if isinstance(parameter.default, (list, dict, set))
if parameter.has_default and is_mutable(parameter.default)
]
assert not params_with_mutable_defaults, (