From 8c5a69eb4727d4fc09d02cdc8c15f89e4aa6ec7e Mon Sep 17 00:00:00 2001 From: Jakob Stoklund Olesen Date: Fri, 3 Mar 2017 09:04:29 -0800 Subject: [PATCH] Fixed for mypy 0.501. The List and Dict types are no longer implicitly available. They must be imported from typing. Type annotations must appear before the doc comment in a function. Also fix type errors in these functions that weren't detected before. --- lib/cretonne/meta/cdsl/ast.py | 14 +++++++------- lib/cretonne/meta/cdsl/formats.py | 2 +- lib/cretonne/meta/cdsl/instructions.py | 2 +- lib/cretonne/meta/cdsl/isa.py | 2 +- lib/cretonne/meta/cdsl/registers.py | 2 +- lib/cretonne/meta/cdsl/types.py | 5 +++++ lib/cretonne/meta/cdsl/xform.py | 2 +- lib/cretonne/meta/gen_instr.py | 7 +++++++ lib/cretonne/meta/gen_registers.py | 2 +- lib/cretonne/meta/isa/__init__.py | 5 +++++ lib/cretonne/meta/srcgen.py | 2 +- 11 files changed, 31 insertions(+), 14 deletions(-) diff --git a/lib/cretonne/meta/cdsl/ast.py b/lib/cretonne/meta/cdsl/ast.py index ddcc702575..931cc1e3a2 100644 --- a/lib/cretonne/meta/cdsl/ast.py +++ b/lib/cretonne/meta/cdsl/ast.py @@ -143,22 +143,22 @@ class Var(Expr): def is_input(self): # type: () -> bool """Is this an input value to the src pattern?""" - return not self.src_def and not self.dst_def + return self.src_def is None and self.dst_def is None def is_output(self): - """Is this an output value, defined in both src and dst patterns?""" # type: () -> bool - return self.src_def and self.dst_def + """Is this an output value, defined in both src and dst patterns?""" + return self.src_def is not None and self.dst_def is not None def is_intermediate(self): - """Is this an intermediate value, defined only in the src pattern?""" # type: () -> bool - return self.src_def and not self.dst_def + """Is this an intermediate value, defined only in the src pattern?""" + return self.src_def is not None and self.dst_def is None def is_temp(self): - """Is this a temp value, defined only in the dst pattern?""" # type: () -> bool - return not self.src_def and self.dst_def + """Is this a temp value, defined only in the dst pattern?""" + return self.src_def is None and self.dst_def is not None def get_typevar(self): # type: () -> TypeVar diff --git a/lib/cretonne/meta/cdsl/formats.py b/lib/cretonne/meta/cdsl/formats.py index 32f4463ae0..974ca80541 100644 --- a/lib/cretonne/meta/cdsl/formats.py +++ b/lib/cretonne/meta/cdsl/formats.py @@ -6,7 +6,7 @@ from .operands import Operand # noqa # The typing module is only required by mypy, and we don't use these imports # outside type comments. try: - from typing import Tuple, Union, Any, Sequence, Iterable # noqa + from typing import Dict, List, Tuple, Union, Any, Sequence, Iterable # noqa except ImportError: pass diff --git a/lib/cretonne/meta/cdsl/instructions.py b/lib/cretonne/meta/cdsl/instructions.py index 84968c1b6b..4040e5338b 100644 --- a/lib/cretonne/meta/cdsl/instructions.py +++ b/lib/cretonne/meta/cdsl/instructions.py @@ -6,7 +6,7 @@ from .operands import Operand from .formats import InstructionFormat try: - from typing import Union, Sequence + from typing import Union, Sequence, List # noqa # List of operands for ins/outs: OpList = Union[Sequence[Operand], Operand] MaybeBoundInst = Union['Instruction', 'BoundInstruction'] diff --git a/lib/cretonne/meta/cdsl/isa.py b/lib/cretonne/meta/cdsl/isa.py index 0065e4e907..7e4c09e58d 100644 --- a/lib/cretonne/meta/cdsl/isa.py +++ b/lib/cretonne/meta/cdsl/isa.py @@ -6,7 +6,7 @@ from .registers import RegClass, Register # The typing module is only required by mypy, and we don't use these imports # outside type comments. try: - from typing import Tuple, Union, Any, Iterable, Sequence, TYPE_CHECKING # noqa + from typing import Tuple, Union, Any, Iterable, Sequence, List, Set, TYPE_CHECKING # noqa from .instructions import MaybeBoundInst, InstructionGroup, InstructionFormat # noqa from .predicates import Predicate, FieldPredicate # noqa from .settings import SettingGroup # noqa diff --git a/lib/cretonne/meta/cdsl/registers.py b/lib/cretonne/meta/cdsl/registers.py index 99dd453aec..003ce6379c 100644 --- a/lib/cretonne/meta/cdsl/registers.py +++ b/lib/cretonne/meta/cdsl/registers.py @@ -26,7 +26,7 @@ from . import is_power_of_two, next_power_of_two try: - from typing import Sequence, Tuple # noqa + from typing import Sequence, Tuple, List, Dict # noqa from .isa import TargetISA # noqa # A tuple uniquely identifying a register class inside a register bank. # (count, width, start) diff --git a/lib/cretonne/meta/cdsl/types.py b/lib/cretonne/meta/cdsl/types.py index 62334b7dd7..f96c5a2ef0 100644 --- a/lib/cretonne/meta/cdsl/types.py +++ b/lib/cretonne/meta/cdsl/types.py @@ -2,6 +2,11 @@ from __future__ import absolute_import import math +try: + from typing import Dict, List # noqa +except ImportError: + pass + # ValueType instances (i8, i32, ...) are provided in the cretonne.types module. class ValueType(object): diff --git a/lib/cretonne/meta/cdsl/xform.py b/lib/cretonne/meta/cdsl/xform.py index ee6710a79f..deca293e50 100644 --- a/lib/cretonne/meta/cdsl/xform.py +++ b/lib/cretonne/meta/cdsl/xform.py @@ -5,7 +5,7 @@ from __future__ import absolute_import from .ast import Def, Var, Apply try: - from typing import Union, Iterator, Sequence, Iterable # noqa + from typing import Union, Iterator, Sequence, Iterable, List, Dict # noqa from .ast import Expr # noqa DefApply = Union[Def, Apply] except ImportError: diff --git a/lib/cretonne/meta/gen_instr.py b/lib/cretonne/meta/gen_instr.py index 8cf89e7654..166967698e 100644 --- a/lib/cretonne/meta/gen_instr.py +++ b/lib/cretonne/meta/gen_instr.py @@ -14,6 +14,13 @@ from cdsl.instructions import Instruction # noqa from cdsl.operands import Operand # noqa from cdsl.typevar import TypeVar # noqa +# The typing module is only required by mypy, and we don't use these imports +# outside type comments. +try: + from typing import List # noqa +except ImportError: + pass + def gen_formats(fmt): # type: (srcgen.Formatter) -> None diff --git a/lib/cretonne/meta/gen_registers.py b/lib/cretonne/meta/gen_registers.py index e36434f4d6..7dfdc45d00 100644 --- a/lib/cretonne/meta/gen_registers.py +++ b/lib/cretonne/meta/gen_registers.py @@ -6,7 +6,7 @@ from __future__ import absolute_import import srcgen try: - from typing import Sequence # noqa + from typing import Sequence, List # noqa from cdsl.isa import TargetISA # noqa from cdsl.registers import RegBank, RegClass # noqa except ImportError: diff --git a/lib/cretonne/meta/isa/__init__.py b/lib/cretonne/meta/isa/__init__.py index 8f623d18bb..bad91c5c90 100644 --- a/lib/cretonne/meta/isa/__init__.py +++ b/lib/cretonne/meta/isa/__init__.py @@ -9,6 +9,11 @@ from __future__ import absolute_import from cdsl.isa import TargetISA # noqa from . import riscv, intel, arm32, arm64 +try: + from typing import List # noqa +except ImportError: + pass + def all_isas(): # type: () -> List[TargetISA] diff --git a/lib/cretonne/meta/srcgen.py b/lib/cretonne/meta/srcgen.py index 75b102f534..e87c16a577 100644 --- a/lib/cretonne/meta/srcgen.py +++ b/lib/cretonne/meta/srcgen.py @@ -11,7 +11,7 @@ import os import re try: - from typing import Any # noqa + from typing import Any, List # noqa except ImportError: pass