diff --git a/spherogram_src/graphs.py b/spherogram_src/graphs.py index b5c3196..acc69b0 100644 --- a/spherogram_src/graphs.py +++ b/spherogram_src/graphs.py @@ -84,7 +84,7 @@ def __hash__(self): def incident_to(self): return list(self) - def is_loop(self): + def is_loop(self) -> bool: return self[0] is self[1] @@ -374,7 +374,7 @@ def components(self, deleted_vertices=[]): result.append(frozenset(component)) return result - def is_connected(self, deleted_vertices=[]): + def is_connected(self, deleted_vertices=[]) -> bool: """ Determine whether the graph obtained by removing the deleted_vertices and incident edges is connected. @@ -391,7 +391,7 @@ def reduced(self): R.add_edge(*e) return R - def is_planar(self): + def is_planar(self) -> bool: return self.reduced().is_planar() def merge(self, V1, V2): @@ -478,7 +478,7 @@ def multi_valence(self, vertex): """ return sum(e.multiplicity for e in self.incidence_dict[vertex]) - def is_planar(self): + def is_planar(self) -> bool: """ Return the planarity. """ @@ -697,14 +697,14 @@ def components(self): raise ValueError('Not meaningful for Digraphs.\n' 'Use weak_components() or strong_components()') - def is_weakly_connected(self): + def is_weakly_connected(self) -> bool: """ A digraph is weakly connected if the associated undirected graph is connected. """ return len(self.weak_components()) <= 1 - def is_connected(self): + def is_connected(self) -> bool: """ A digraph is connected if, for every pair of vertices v, w, there is either a directed path from v to w or a directed path @@ -732,7 +732,7 @@ def strong_components(self): """ return StrongConnector(self).components - def is_strongly_connected(self): + def is_strongly_connected(self) -> bool: """ A digraph is strongly connected if, for every pair of vertices v, w, there is a directed path from v to w and a directed path diff --git a/spherogram_src/links/bands/core.py b/spherogram_src/links/bands/core.py index eae954a..e22c044 100644 --- a/spherogram_src/links/bands/core.py +++ b/spherogram_src/links/bands/core.py @@ -313,7 +313,7 @@ def __ge__(self, other): def __repr__(self): return f'Band{self._spec}' - def is_nonminimal(self, link=None): + def is_nonminimal(self, link=None) -> bool: """ Do various tests to see if self is obviously equivalent to a band other with other < self. diff --git a/spherogram_src/links/bands/search.py b/spherogram_src/links/bands/search.py index b49e68d..d73f7f3 100644 --- a/spherogram_src/links/bands/search.py +++ b/spherogram_src/links/bands/search.py @@ -3,7 +3,7 @@ from .core import Band, add_one_band, banded_links, normalize_crossing_labels -def linking_nums_all_zero(link): +def linking_nums_all_zero(link) -> bool: """ >>> linking_nums_all_zero(Link('L2a1')) # Hopf False @@ -13,7 +13,7 @@ def linking_nums_all_zero(link): return all(x == 0 for row in link.linking_matrix() for x in row) -def is_unlink_exterior(manifold): +def is_unlink_exterior(manifold) -> bool: """ If there is clearly a hyperbolic structure present, we don't even look at the fundamental group as it takes some time to compute and @@ -24,7 +24,7 @@ def is_unlink_exterior(manifold): return manifold.fundamental_group().num_relators() == 0 -def could_be_strongly_slice(link): +def could_be_strongly_slice(link) -> bool: """ Checks several obstructions for a link L to be strongly slice, that is that all components of L simultaneously bound embedded diff --git a/spherogram_src/links/exhaust.py b/spherogram_src/links/exhaust.py index 84b604d..285a5a3 100644 --- a/spherogram_src/links/exhaust.py +++ b/spherogram_src/links/exhaust.py @@ -256,12 +256,14 @@ def _check(self): return sorted(self.int_to_set) == list(range(self.n)) -def is_range(L): +def is_range(L) -> bool: """ >>> is_range([2, 3, 4]), is_range([2, 3, 5]) (True, False) """ - return L == list(range(min(L), max(L) + 1)) + if not L: + return False + return all(i == Li for i, Li in enumerate(L, start=L[0])) class Frontier(BiDict): diff --git a/spherogram_src/links/jones.py b/spherogram_src/links/jones.py index 9ebb272..d481452 100644 --- a/spherogram_src/links/jones.py +++ b/spherogram_src/links/jones.py @@ -160,8 +160,8 @@ def add_positive_crossing(self, i): def add_negative_crossing(self, i): return self.cap_then_cup(i) + (-q) * self - def is_multiple_of_empty_pairing(self): - return len(self.dict) == 1 and (PerfectMatching([]) in self.dict) + def is_multiple_of_empty_pairing(self) -> bool: + return len(self.dict) == 1 and PerfectMatching([]) in self.dict def kauffman_bracket(link): diff --git a/spherogram_src/links/jones_old.py b/spherogram_src/links/jones_old.py index 038a253..56af55d 100644 --- a/spherogram_src/links/jones_old.py +++ b/spherogram_src/links/jones_old.py @@ -32,7 +32,7 @@ def cut(G, T, e): return answer -def is_internally_active(G, T, e): +def is_internally_active(G, T, e) -> bool: """ Input: --A graph G. @@ -88,7 +88,7 @@ def cyc(G, T, e): return answer -def is_externally_active(G, T, e): +def is_externally_active(G, T, e) -> bool: """ Input: --A graph G. diff --git a/spherogram_src/links/links_base.py b/spherogram_src/links/links_base.py index 006b7b7..d57fc6d 100644 --- a/spherogram_src/links/links_base.py +++ b/spherogram_src/links/links_base.py @@ -33,7 +33,7 @@ def __getitem__(self, n): # Helper function. -def is_iterable(obj): +def is_iterable(obj) -> bool: try: iter(obj) return True @@ -149,13 +149,12 @@ def orient(self): self.rotate_by_180() self.sign = 1 if (3, 1) in self.directions else -1 - def is_incoming(self, i): + def is_incoming(self, i) -> bool: if self.sign == 1: return i in (0, 3) - elif self.sign == -1: + if self.sign == -1: return i in (0, 1) - else: - raise ValueError('Crossing not oriented') + raise ValueError('Crossing not oriented') def __getitem__(self, i): return (self, i % 4) @@ -281,10 +280,10 @@ def other(self): other = nonzero_entry_point if self.strand_index == 0 else 0 return CrossingEntryPoint(self.crossing, other) - def is_under_crossing(self): + def is_under_crossing(self) -> bool: return self.strand_index == 0 - def is_over_crossing(self): + def is_over_crossing(self) -> bool: return self.strand_index != 0 def component(self): @@ -362,7 +361,7 @@ def format_adjacent(a): print("<%s : %s>" % (self.label, [format_adjacent(a) for a in self.adjacent])) - def is_loop(self): + def is_loop(self) -> bool: return self == self.adjacent[0][0] @@ -947,7 +946,7 @@ def digraph(self): G.add_edge(cs0.crossing, cs1.crossing) return G - def is_planar(self): + def is_planar(self) -> bool: """ Whether the 4-valent graph underlying the link projection is planar. @@ -989,7 +988,7 @@ def is_planar(self): euler = -v + len(self.faces()) return euler == 2 or v == 0 - def is_alternating(self): + def is_alternating(self) -> bool: """ Returns whether or not this link diagram is alternating. @@ -1225,10 +1224,8 @@ def PD_code(self, KnotTheory=False, min_strand_index=0): >>> [len(c) for c in L_copy.link_components] [4, 4, 4, 6, 8] """ - PD = [] - - for c in self.crossings: - PD.append([s + min_strand_index for s in c.strand_labels]) + PD = [[s + min_strand_index for s in c.strand_labels] + for c in self.crossings] if KnotTheory: PD = "PD" + repr(PD).replace('[', 'X[')[1:] else: diff --git a/spherogram_src/links/morse.py b/spherogram_src/links/morse.py index 414f6ea..fe65aea 100644 --- a/spherogram_src/links/morse.py +++ b/spherogram_src/links/morse.py @@ -339,7 +339,7 @@ def pack_snakes(self): self.snakes_at_height = snakes_at_height - def is_bridge(self): + def is_bridge(self) -> bool: """ Returns whether the link is in bridge position with respect to this height function. @@ -431,5 +431,5 @@ def HF(self): import bohua_HF return bohua_HF.compute_HF(self.bohua_code()) - def is_proper(self): + def is_proper(self) -> bool: return all(abs(a - b) < 2 for a, b in self.crossings) diff --git a/spherogram_src/links/orthogonal.py b/spherogram_src/links/orthogonal.py index b6df570..d08c9bb 100644 --- a/spherogram_src/links/orthogonal.py +++ b/spherogram_src/links/orthogonal.py @@ -156,7 +156,7 @@ def kitty_corner(self): if not self.exterior: return kitty_corner(self.turns) - def is_turn_regular(self): + def is_turn_regular(self) -> bool: return self.kitty_corner() is None def switches(self, swap_hor_edges): @@ -416,11 +416,10 @@ def orient_edges(self, edge, orientation): dir = (dir + t) % 4 return ans - def is_turn_regular(self): + def is_turn_regular(self) -> bool: if self.exterior: return True - else: - return kitty_corner(self.turns) is None + return kitty_corner(self.turns) is None def __repr__(self): ext = '*' if self.exterior else '' diff --git a/spherogram_src/links/seifert.py b/spherogram_src/links/seifert.py index 366d2be..b6821be 100644 --- a/spherogram_src/links/seifert.py +++ b/spherogram_src/links/seifert.py @@ -149,7 +149,7 @@ def isotope_to_braid(link): pass -def is_chain(tree): +def is_chain(tree) -> bool: tails = [e[0] for e in tree] heads = [e[1] for e in tree] return len(set(tails)) == len(tails) and len(set(heads)) == len(heads)