Changeset View
Changeset View
Standalone View
Standalone View
release/scripts/modules/bpy_types.py
| Show First 20 Lines • Show All 50 Lines • ▼ Show 20 Lines | def path_resolve(self, path, coerce=True): | ||||
| # to simplify exception handling for the caller. | # to simplify exception handling for the caller. | ||||
| value = getattr(self, attr, _sentinel) | value = getattr(self, attr, _sentinel) | ||||
| if value is _sentinel: | if value is _sentinel: | ||||
| raise ValueError("Path could not be resolved: %r" % attr) | raise ValueError("Path could not be resolved: %r" % attr) | ||||
| if value is None: | if value is None: | ||||
| return value | return value | ||||
| # If the attribute is a list property, apply subscripting. | |||||
| if isinstance(value, list) and path_rest.startswith("["): | |||||
| index_str, div, index_tail = path_rest[1:].partition("]") | |||||
| if not div: | |||||
| raise ValueError(f"Path index is not terminated: {attr}{path_rest}") | |||||
campbellbarton: The convention for built-in scripts is to use `%` formatting. | |||||
| if not index_str.isdigit(): | |||||
| raise ValueError(f"Path index is invalid: {attr}[{index_str}]") | |||||
| index = int(index_str) | |||||
campbellbartonUnsubmitted Not Done Inline ActionsNon-integer values (such as slice or bad input) will error here. There should be a check for non-integer values (if int fails). campbellbarton: Non-integer values (such as slice or bad input) will error here.
There should be a check for… | |||||
angavrilovAuthorUnsubmitted Done Inline ActionsThe isdigit check is supposed to test for that, unless you mean integer overflow or something. angavrilov: The isdigit check is supposed to test for that, unless you mean integer overflow or something. | |||||
| path_rest = index_tail | |||||
| if 0 <= index < len(value): | |||||
| value = value[index] | |||||
| else: | |||||
| raise IndexError(f"Path index out of range: {attr}[{index_str}]") | |||||
| # Resolve the rest of the path if necessary. | # Resolve the rest of the path if necessary. | ||||
| if path_rest: | if path_rest: | ||||
| path_resolve_fn = getattr(value, "path_resolve", None) | path_resolve_fn = getattr(value, "path_resolve", None) | ||||
| if path_resolve_fn is None: | if path_resolve_fn is None: | ||||
| raise ValueError("Path %s resolves to a non RNA value" % attr) | raise ValueError("Path %s resolves to a non RNA value" % attr) | ||||
| return path_resolve_fn(path_rest, coerce) | return path_resolve_fn(path_rest, coerce) | ||||
| return value | return value | ||||
| ▲ Show 20 Lines • Show All 1,087 Lines • Show Last 20 Lines | |||||
The convention for built-in scripts is to use % formatting.