diff --git a/kwant/builder.py b/kwant/builder.py index 99313b694b396d688ede3b1a189bd6cbfe986b7f..3b66ef9600802a770eaeabc3c3b90e1ef3b64026 100644 --- a/kwant/builder.py +++ b/kwant/builder.py @@ -432,13 +432,11 @@ def for_each_in_key(key, f_site, f_hopp): f_hopp(hopping) else: raise KeyError(first) - else: - raise KeyError(key) -# Marker which means for hopping (i, j): this value is given by the Hermitian +# A marker, meaning for hopping (i, j): this value is given by the Hermitian # conjugate the value of the hopping (j, i). Used by Builder and System. -other = [] +Other = type('Other', (object,), {'__repr__': lambda s: 'Other'})() def edges(seq): @@ -622,7 +620,7 @@ class Builder(object): value = self._get_edge(a, b) except ValueError: raise KeyError(hopping) - if value is other: + if value is Other: if not sym.in_fd(b): b, a = sym.to_fd(b, a) assert not sym.in_fd(a) @@ -687,14 +685,14 @@ class Builder(object): a = self.H[a][0] # Might fail. b = self.H[b][0] # Might fail. self._set_edge(a, b, value) # Will work. - self._set_edge(b, a, other) # Will work. + self._set_edge(b, a, Other) # Will work. else: b2, a2 = sym.to_fd(b, a) if b2 not in self.H: raise KeyError() assert not sym.in_fd(a2) self._set_edge(a, b, value) # Might fail. - self._set_edge(b2, a2, other) # Will work. + self._set_edge(b2, a2, Other) # Will work. except KeyError: raise KeyError(hopping) @@ -797,7 +795,7 @@ class Builder(object): """ for tail, hvhv in self.H.iteritems(): for head, value in edges(hvhv): - if value is other: + if value is Other: continue yield (tail, head) @@ -805,7 +803,7 @@ class Builder(object): """Return an iterator over all (hopping, value) pairs.""" for tail, hvhv in self.H.iteritems(): for head, value in edges(hvhv): - if value is other: + if value is Other: continue yield (tail, head), value @@ -1189,7 +1187,7 @@ class FiniteSystem(system.FiniteSystem): else: edge_id = self.graph.first_edge_id(i, j) value = self.hoppings[edge_id] - conj = value is other + conj = value is Other if conj: i, j = j, i edge_id = self.graph.first_edge_id(i, j) @@ -1222,7 +1220,7 @@ class InfiniteSystem(system.InfiniteSystem): else: edge_id = self.graph.first_edge_id(i, j) value = self.hoppings[edge_id] - conj = value is other + conj = value is Other if conj: i, j = j, i edge_id = self.graph.first_edge_id(i, j) diff --git a/kwant/tests/test_builder.py b/kwant/tests/test_builder.py index 428840950dc2c15a740e2a99212d24c2f74127a8..44b73f889c910b2ff7007bcc028ef40f5d860403 100644 --- a/kwant/tests/test_builder.py +++ b/kwant/tests/test_builder.py @@ -208,7 +208,7 @@ def check_hoppings(fsys, hops): tail = fsys.site(tail).tag head = fsys.site(head).tag value = fsys.hoppings[edge_id] - if value is builder.other: + if value is builder.Other: assert (head, tail) in hops else: assert (tail, head) in hops