From 4afa19ddff99da15b973d9025d9686fdff4f5b42 Mon Sep 17 00:00:00 2001 From: Jakob Stoklund Olesen Date: Wed, 3 Jan 2018 12:13:13 -0800 Subject: [PATCH] Fix some mypy errors. It looks like mypy 0.560 doesn't like when a local variable changes its type inside a function. Fixes introduce a new variable instead of reusing an existing one. --- lib/cretonne/meta/cdsl/instructions.py | 16 ++++++++-------- lib/cretonne/meta/unique_table.py | 17 ++++++++++------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/lib/cretonne/meta/cdsl/instructions.py b/lib/cretonne/meta/cdsl/instructions.py index 2ca4951c58..3ef95c9cf9 100644 --- a/lib/cretonne/meta/cdsl/instructions.py +++ b/lib/cretonne/meta/cdsl/instructions.py @@ -290,12 +290,12 @@ class Instruction(object): # Allow a single Operand instance instead of the awkward singleton # tuple syntax. if isinstance(x, Operand): - x = (x,) + y = (x,) # type: Tuple[Operand, ...] else: - x = tuple(x) - for op in x: + y = tuple(x) + for op in y: assert isinstance(op, Operand) - return x + return y @staticmethod def _to_constraint_tuple(x): @@ -307,12 +307,12 @@ class Instruction(object): # import placed here to avoid circular dependency from .ti import TypeConstraint # noqa if isinstance(x, TypeConstraint): - x = (x,) + y = (x,) # type: Tuple[TypeConstraint, ...] else: - x = tuple(x) - for op in x: + y = tuple(x) + for op in y: assert isinstance(op, TypeConstraint) - return x + return y def bind(self, *args): # type: (*ValueType) -> BoundInstruction diff --git a/lib/cretonne/meta/unique_table.py b/lib/cretonne/meta/unique_table.py index 0e18ae3afd..d8482b3c7d 100644 --- a/lib/cretonne/meta/unique_table.py +++ b/lib/cretonne/meta/unique_table.py @@ -62,16 +62,19 @@ class UniqueSeqTable: """ if len(seq) == 0: return 0 - seq = tuple(seq) - if seq in self.index: - return self.index[seq] + tseq = tuple(seq) + if tseq in self.index: + return self.index[tseq] idx = len(self.table) - self.table.extend(seq) + self.table.extend(tseq) # Add seq and all sub-sequences to `index`. - for length in range(1, len(seq) + 1): - for offset in range(len(seq) - length + 1): - self.index[seq[offset:offset+length]] = idx + offset + index = self.index # type: Dict[Tuple[Any, ...], int] + assert index is not None + for length in range(1, len(tseq) + 1): + for offset in range(len(tseq) - length + 1): + key = tseq[offset:offset+length] + index[key] = idx + offset return idx