-
Notifications
You must be signed in to change notification settings - Fork 35
schemaview.py: check for a valid slot def before calling a function #480
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -465,8 +465,7 @@ def imports_closure( | |
| # visit item | ||
| sn = todo.pop() | ||
| if sn not in self.schema_map: | ||
| imported_schema = self.load_import(sn) | ||
| self.schema_map[sn] = imported_schema | ||
| self.schema_map[sn] = self.load_import(sn) | ||
|
|
||
| # resolve item's imports if it has not been visited already | ||
| # we will get duplicates, but not cycles this way, and | ||
|
|
@@ -1904,6 +1903,10 @@ def slot_applicable_range_elements(self, slot: SlotDefinition) -> list[ClassDefi | |
| :param slot: | ||
| :return: list of element types | ||
| """ | ||
| if not slot or not isinstance(slot, SlotDefinition): | ||
| err_msg = "A SlotDefinition must be provided to generate the slot applicable range elements." | ||
| raise ValueError(err_msg) | ||
|
|
||
|
Comment on lines
+1906
to
+1909
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wouldn't it make sense to have a function for this purpose, since the same validation is being applied in multiple places? I mean something like def _validate_slot(slot, err_sfx) -> None:
if not slot or not isinstance(slot, SlotDefinition):
raise ValueError(
f"A SlotDefinition must be provided to generate the {err_sfx}."
)BTW you are typically optimizing. I don't get why you use the variable
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Feel free to resolve comment, and merge, if desired
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the https://docs.astral.sh/ruff/rules/raw-string-in-exception/ You are absolutely right about optimising by creating a generic function. I don't know why I didn't do it - end of the workday, maybe?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're right, I forgot that recommendation 😄
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm going to investigate options because as soon as I see a verification function like that, I want to make it more generic. I need to get my core work done and then I'll dedicate some time to thinking/researching argument validation. |
||
| is_any = False | ||
| range_types = [] | ||
| for r in self.slot_range_as_union(slot): | ||
|
|
@@ -1930,6 +1933,10 @@ def slot_range_as_union(self, slot: SlotDefinition) -> list[ElementName]: | |
| :param slot: | ||
| :return: list of ranges | ||
| """ | ||
| if not slot or not isinstance(slot, SlotDefinition): | ||
| err_msg = "A SlotDefinition must be provided to generate the slot range as union." | ||
| raise ValueError(err_msg) | ||
|
|
||
| return list({y.range for y in [slot, *[x for x in [*slot.exactly_one_of, *slot.any_of] if x.range]]}) | ||
|
|
||
| def induced_slot_range(self, slot: SlotDefinition, strict: bool = False) -> set[str | ElementName]: # noqa: FBT001, FBT002 | ||
|
|
@@ -1947,6 +1954,9 @@ def induced_slot_range(self, slot: SlotDefinition, strict: bool = False) -> set[ | |
| :return: set of ranges | ||
| :rtype: set[str | ElementName] | ||
| """ | ||
| if not slot or not isinstance(slot, SlotDefinition): | ||
| err_msg = "A SlotDefinition must be provided to generate the induced slot range." | ||
| raise ValueError(err_msg) | ||
|
|
||
| slot_range = slot.range | ||
| any_of_range = {x.range for x in slot.any_of if x.range} | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.