added Node typevar

This commit is contained in:
Marcell Vazquez-Chanlatte 2018-12-19 11:27:38 -08:00
parent ba56886a4d
commit c0b1dfd5ec
2 changed files with 14 additions and 8 deletions

View file

@ -15,7 +15,10 @@
version="1.1" version="1.1"
id="svg8" id="svg8"
inkscape:version="0.92.3 (2405546, 2018-03-11)" inkscape:version="0.92.3 (2405546, 2018-03-11)"
sodipodi:docname="logo_text.svg"> sodipodi:docname="logo_text.svg"
inkscape:export-filename="/home/mvc/work/research/py-stl/assets/logo.png"
inkscape:export-xdpi="99.997803"
inkscape:export-ydpi="99.997803">
<defs <defs
id="defs2"> id="defs2">
<marker <marker

Before

Width:  |  Height:  |  Size: 7.7 KiB

After

Width:  |  Height:  |  Size: 7.8 KiB

Before After
Before After

View file

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from collections import deque from collections import deque
from typing import Union, NamedTuple from typing import Union, NamedTuple, TypeVar
import attr import attr
import funcy as fn import funcy as fn
@ -9,6 +9,9 @@ from lenses import bind
from mtl import sugar from mtl import sugar
Node = TypeVar("Node")
def flatten_binary(phi, op, dropT, shortT): def flatten_binary(phi, op, dropT, shortT):
def f(x): def f(x):
return x.args if isinstance(x, op) else [x] return x.args if isinstance(x, op) else [x]
@ -173,7 +176,7 @@ class Interval(NamedTuple):
@ast_class @ast_class
class NaryOpMTL: class NaryOpMTL:
OP = "?" OP = "?"
args: "Node" # TODO: when 3.7 is more common replace with type union. args: Node # TODO: when 3.7 is more common replace with type union.
def __repr__(self): def __repr__(self):
return "(" + f" {self.OP} ".join(f"{x}" for x in self.args) + ")" return "(" + f" {self.OP} ".join(f"{x}" for x in self.args) + ")"
@ -191,7 +194,7 @@ class And(NaryOpMTL):
class ModalOp: class ModalOp:
OP = '?' OP = '?'
interval: Interval interval: Interval
arg: "Node" arg: Node
def __repr__(self): def __repr__(self):
if self.interval.lower == 0 and self.interval.upper == float('inf'): if self.interval.lower == 0 and self.interval.upper == float('inf'):
@ -209,8 +212,8 @@ class G(ModalOp):
@ast_class @ast_class
class WeakUntil: class WeakUntil:
arg1: "Node" arg1: Node
arg2: "Node" arg2: Node
def __repr__(self): def __repr__(self):
return f"({self.arg1} W {self.arg2})" return f"({self.arg1} W {self.arg2})"
@ -222,7 +225,7 @@ class WeakUntil:
@ast_class @ast_class
class Neg: class Neg:
arg: "Node" arg: Node
def __repr__(self): def __repr__(self):
return f"~{self.arg}" return f"~{self.arg}"
@ -234,7 +237,7 @@ class Neg:
@ast_class @ast_class
class Next: class Next:
arg: "Node" arg: Node
def __repr__(self): def __repr__(self):
return f"X{self.arg}" return f"X{self.arg}"