Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: validate the setting of Options values #386

Open
machow opened this issue Jun 28, 2024 · 0 comments
Open

Refactor: validate the setting of Options values #386

machow opened this issue Jun 28, 2024 · 0 comments

Comments

@machow
Copy link
Collaborator

machow commented Jun 28, 2024

Currently, Great Tables models a wide range of options via the Options dataclass. This class looks like this...

@dataclass(frozen=True)
class OptionsInfo:
    scss: bool
    category: str
    type: str
    value: Any

@dataclass(frozen=True)
class Options:
    table_id: OptionsInfo = OptionsInfo(False, "table", "value", None)
    table_caption: OptionsInfo = OptionsInfo(False, "table", "value", None)

Notice three things it defines:

  • options names (e.g. table_id)
  • roughly, the part of the table they apply to (e.g. "table")
  • their 'type' in a loose sense (a string that could be "value", "px", some other things)
  • The default value (e.g. None)

Problem: These are used in a few places, like scss template rendering. However, there's a big challenge we don't have info to address: validating the type when setting options. If we could specify the types accepted for an option (e.g. in OptionInfo), we could automate validating the setting of options by users (e.g. OptionInfo.set(), or .validate() etc..).

Benefit: This would ensure users don't get too far before hitting errors due to invalid option types. It will consolidate the misc code we use to validate into one place, and apply validation consistently.

Examples of custom validation today

If you search for the tab_options() function, validations often happen before it's called. For example, when .opt_table_align_header() sets the heading_align option.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant