added check to ensure default attachments are instances

This commit is contained in:
Jakob Pinterits
2024-06-04 19:02:00 +02:00
parent 8b8e68523b
commit fa75a54e11
2 changed files with 10 additions and 3 deletions
+8
View File
@@ -262,6 +262,14 @@ class App:
if theme is None:
theme = rio.Theme.from_colors()
# A common mistake is to pass types instead of instances to
# `default_attachments`. Catch that, scream and die.
for attachment in default_attachments:
if isinstance(attachment, type):
raise TypeError(
f"Default attachments should be instances, not types. Did you mean to type `{attachment.__name__}()`?"
)
# The `main_file` isn't detected correctly if the app is launched via
# `rio run`. We'll store the user input so that `rio run` can fix the
# assets dir.
+2 -3
View File
@@ -104,9 +104,8 @@ class UserSettings(metaclass=RioDataclassMeta):
settings_json: uniserde.JsonDoc,
defaults: Self,
) -> Self:
# Create the instance for this attachment. Bypass the constructor so
# the instance doesn't immediately try to synchronize with the
# frontend.
# Create the instance for this attachment. Bypass the constructor so the
# instance doesn't immediately try to synchronize with the frontend.
self = object.__new__(cls)
settings_vars = vars(self)