From c5a71be509d20c28f6bb469bc67136d258ae9125 Mon Sep 17 00:00:00 2001 From: Salvo 'LtWorf' Tomaselli Date: Sun, 14 Jun 2020 22:43:50 +0200 Subject: [PATCH] Tell mypy about the values of name in nodes --- relational/parser.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/relational/parser.py b/relational/parser.py index 89862d0..41c0e98 100644 --- a/relational/parser.py +++ b/relational/parser.py @@ -24,7 +24,7 @@ # # Language definition here: # http://ltworf.github.io/relational/grammar.html -from typing import Optional, Union, List, Any, Dict +from typing import Optional, Union, List, Any, Dict, Literal from dataclasses import dataclass from relational import rtypes @@ -43,6 +43,11 @@ SELECTION = 'σ' RENAME = 'ρ' ARROW = '➡' +BINARY_LITERALS_T = Literal['*', '-', '∪', '∩', '÷', '⋈', '⧑', '⧒', '⧓'] + +UNARY_LITERALS_T = Literal['π', 'σ', 'ρ'] + + b_operators = (PRODUCT, DIFFERENCE, UNION, INTERSECTION, DIVISION, JOIN, JOIN_LEFT, JOIN_RIGHT, JOIN_FULL) # List of binary operators u_operators = (PROJECTION, SELECTION, RENAME) # List of unary operators @@ -194,6 +199,7 @@ class Variable(Node): @dataclass class Binary(Node): + name: BINARY_LITERALS_T left: Node right: Node @@ -214,6 +220,7 @@ class Binary(Node): @dataclass class Unary(Node): + name: UNARY_LITERALS_T prop: str child: Node