Skip to content
This repository has been archived by the owner on Nov 11, 2021. It is now read-only.

Allow type variables in Nodes #58

Open
tehrengruber opened this issue Sep 1, 2020 · 0 comments
Open

Allow type variables in Nodes #58

tehrengruber opened this issue Sep 1, 2020 · 0 comments
Assignees
Labels
eve Related to eve infrastructure

Comments

@tehrengruber
Copy link
Contributor

tehrengruber commented Sep 1, 2020

It is sometimes useful to restrict types of fields of fields of a node.

Objectives

  • Reduce the amount of verification boilerplate code inside the translators.
  • Reduce the amount of state to be passed to child nodes inside the translators
  • Elimination of redundant nodes

Pydantic supports this out of the box (see pydantic/pydantic#556 and pydantic/pydantic#595).

Open questions:

  1. How to check for a field type to be a subtype of generic type? This will be a common question if we allow this, but Python does not allow subclass checks with generic, i.e. the following does not work:
from typing import Generic, TypeVar, List
# raises: TypeError: Subscripted generics cannot be used with class and instance checks
issubclass(List[int], List[T])
  1. Consequences of changing the Node base class to GenericModel
  2. Is this compatible with mypy?

Example 1

T = TypeVar('T')
class Constant(GT4PyAstNode, Generic[T]):
    value: T

class ExampleNode:
    some_int_constant: Constant[Int]

Example 2

T = TypeVar('T')

class Stencil(GTScriptAstNode, Generic[T]):
    iteration_spec: List[Union[IterationOrder, LocationSpecification, Interval]]
    body: List[T]

class Computation(GTScriptAstNode):
    name: str
    arguments: List[Argument]
    stencils: List[Union[Stencil[Stencil[Statement]], Stencil[Statement]]]
@egparedes egparedes added the eve Related to eve infrastructure label Oct 16, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
eve Related to eve infrastructure
Projects
None yet
Development

No branches or pull requests

2 participants