-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
Example:
PlainType = t.Union[str, bool, int, float, "Expression"]
ValueType = t.Union[PlainType, t.List["PlainType"], t.Dict[str, "PlainType"]]
@dataclasses.dataclass
class Attribute(Node):
key: str
value: ValueType
When resolving the schema members of Attribute, we should be able to correctly interpret the "Expression" and "PlainType" forward references. What we currently get is
File "/Users/niklas.rosenstein/gitme/kraken/.venvs/3.10.2/lib/python3.10/site-packages/typeapi/model.py", line 277, in evaluate
raise RuntimeError(f'no module or namespace to evaluate {self}')
RuntimeError: no module or namespace to evaluate ForwardRef('Expression')
A workaround for now is to explicitly pass the module name to a typing.ForwardRef() object:
PlainType = t.Union[str, bool, int, float, t.ForwardRef("Expression", module=__name__)]
ValueType = t.Union[PlainType, t.List[t.ForwardRef("PlainType", module=__name__)], t.Dict[str, t.ForwardRef("PlainType", module=__name__)]]
I think that unfortunately we won't be able to tell where the forward reference was defined originally (i.e. if it was imported from another module, we won't be able to detect that to use that module's scope for evaluation), but at least within the same module of the type that we're evaluating it's members from we should try to resolve it in that type's module.
Metadata
Metadata
Assignees
Labels
No labels