From c93810fa7102f4cd518bb34bfb6b4913bb25fd5b Mon Sep 17 00:00:00 2001 From: "James D. Mitchell" Date: Tue, 15 Feb 2022 11:04:51 +0000 Subject: [PATCH] Some linting --- etc/gaplint.sh | 4 +--- gap/attr.gi | 14 +++++--------- gap/cliques.gi | 18 +++++------------- gap/constructors.gi | 3 +-- gap/digraph.gd | 3 --- gap/examples.gi | 7 ++----- gap/grahom.gi | 3 +-- gap/grape.gi | 4 +--- gap/io.gi | 10 +++------- gap/isomorph.gi | 12 +++--------- gap/oper.gi | 12 +++--------- gap/utils.gi | 3 +-- 12 files changed, 26 insertions(+), 67 deletions(-) diff --git a/etc/gaplint.sh b/etc/gaplint.sh index 8e4062a29..57c8b27e6 100755 --- a/etc/gaplint.sh +++ b/etc/gaplint.sh @@ -1,6 +1,4 @@ #!/bin/bash set -e -gaplint --disable W004 *.g gap/* -gaplint --disable W004 doc/*.xml -gaplint --disable W004 tst/testinstall.tst tst/standard/*.tst tst/extreme/*.tst tst/workspaces/*.tst +gaplint --disable W004 *.g gap/* doc/*.xml tst/testinstall.tst tst/standard/*.tst tst/extreme/*.tst tst/workspaces/*.tst diff --git a/gap/attr.gi b/gap/attr.gi index 470047d1a..e51ea129b 100644 --- a/gap/attr.gi +++ b/gap/attr.gi @@ -1407,15 +1407,13 @@ end); InstallMethod(DigraphBicomponents, "for a digraph", [IsDigraph], function(D) - local b; # Attribute only applies to bipartite digraphs if not IsBipartiteDigraph(D) then return fail; fi; - b := KernelOfTransformation(DIGRAPHS_Bipartite(D)[2], + return KernelOfTransformation(DIGRAPHS_Bipartite(D)[2], DigraphNrVertices(D)); - return b; end); InstallMethod(DigraphLoops, "for a digraph by out-neighbours", @@ -1527,9 +1525,7 @@ function(D) return DigraphVertices(D); elif not IsStronglyConnectedDigraph(D) then return fail; - fi; - - if DigraphNrVertices(D) < 256 then + elif DigraphNrVertices(D) < 256 then path := DigraphMonomorphism(CycleDigraph(DigraphNrVertices(D)), D); if path = fail then return fail; @@ -1733,7 +1729,8 @@ InstallMethodThatReturnsDigraph(ReducedDigraph, "for a digraph by out-neighbours", [IsDigraphByOutNeighboursRep], function(D) - local v, niv, old, C, i; + local v, niv, old, i; + if IsConnectedDigraph(D) then return D; fi; @@ -1749,8 +1746,7 @@ function(D) UniteBlistList(v, niv, old[i]); fi; od; - C := InducedSubdigraph(D, ListBlist(v, niv)); - return C; + return InducedSubdigraph(D, ListBlist(v, niv)); end); InstallMethod(DigraphRemoveAllMultipleEdges, diff --git a/gap/cliques.gi b/gap/cliques.gi index 46db38a40..69a533e5e 100644 --- a/gap/cliques.gi +++ b/gap/cliques.gi @@ -175,8 +175,7 @@ function(arg) ErrorNoReturn("at least 1 argument is required,"); elif not IsDigraph(arg[1]) then ErrorNoReturn("the 1st argument must be a digraph,"); - fi; - if not IsBound(arg[2]) + elif not IsBound(arg[2]) and HasDigraphMaximalIndependentSetsRepsAttr(arg[1]) then return DigraphMaximalIndependentSetsRepsAttr(arg[1]); fi; @@ -203,8 +202,7 @@ function(arg) ErrorNoReturn("at least 1 argument is required,"); elif not IsDigraph(arg[1]) then ErrorNoReturn("the 1st argument must be a digraph,"); - fi; - if not IsBound(arg[2]) + elif not IsBound(arg[2]) and HasDigraphMaximalIndependentSetsAttr(arg[1]) then return DigraphMaximalIndependentSetsAttr(arg[1]); fi; @@ -552,9 +550,7 @@ function(digraph, hook, user_param, limit, include, exclude, max, size, reps) if not IsDigraph(digraph) then ErrorNoReturn("the 1st argument must be a digraph,"); - fi; - - if hook <> fail then + elif hook <> fail then if not (IsFunction(hook) and NumberArgumentsFunction(hook) = 2) then ErrorNoReturn("the 2nd argument must be fail, or a ", "function with 2 arguments,"); @@ -584,14 +580,10 @@ function(digraph, hook, user_param, limit, include, exclude, max, size, reps) if not max in [true, false] then ErrorNoReturn("the 7th argument must be true or false,"); - fi; - - if size <> fail and not IsPosInt(size) then + elif size <> fail and not IsPosInt(size) then ErrorNoReturn("the 8th argument must be fail, or a ", "positive integer,"); - fi; - - if not reps in [true, false] then + elif not reps in [true, false] then ErrorNoReturn("the 9th argument must be true or false,"); fi; diff --git a/gap/constructors.gi b/gap/constructors.gi index c34b42afb..056f9ef9f 100644 --- a/gap/constructors.gi +++ b/gap/constructors.gi @@ -159,8 +159,7 @@ function(D) local G, opt; if not IsSymmetricDigraph(D) then ErrorNoReturn("the argument must be a symmetric digraph,"); - fi; - if HasDigraphGroup(D) then + elif HasDigraphGroup(D) then G := DigraphGroup(D); else G := Group(()); diff --git a/gap/digraph.gd b/gap/digraph.gd index 8c3924bc6..0f21813cb 100644 --- a/gap/digraph.gd +++ b/gap/digraph.gd @@ -80,10 +80,7 @@ DeclareConstructor("DigraphByAdjacencyMatrixConsNC", [IsDigraph, IsHomogeneousList]); DeclareOperation("DigraphByAdjacencyMatrix", [IsFunction, IsHomogeneousList]); -DeclareOperation("DigraphByAdjacencyMatrixNC", [IsFunction, IsHomogeneousList]); - DeclareOperation("DigraphByAdjacencyMatrix", [IsHomogeneousList]); -DeclareOperation("DigraphByAdjacencyMatrixNC", [IsHomogeneousList]); DeclareConstructor("DigraphByEdgesCons", [IsDigraph, IsList]); DeclareConstructor("DigraphByEdgesCons", [IsDigraph, IsList, IsInt]); diff --git a/gap/examples.gi b/gap/examples.gi index 10458d15b..9db299b0e 100644 --- a/gap/examples.gi +++ b/gap/examples.gi @@ -1684,12 +1684,10 @@ InstallMethod(PermutationStarGraph, "for a function and two integers", InstallMethod(PrismGraphCons, "for IsMutableDigraph and an integer", [IsMutableDigraph, IsPosInt], function(filt, n) - local D; if n < 3 then ErrorNoReturn("the argument must be an integer equal to 3 or more,"); else - D := GeneralisedPetersenGraph(IsMutableDigraph, n, 1); - return D; + return GeneralisedPetersenGraph(IsMutableDigraph, n, 1); fi; end); @@ -1797,8 +1795,7 @@ function(filt, n) D := DigraphRemoveEdge(D, i + 1, i); od; D := DigraphRemoveEdge(D, n, 1); - D := DigraphRemoveEdge(D, 1, n); - return D; + return DigraphRemoveEdge(D, 1, n); end); InstallMethod(WebGraphCons, diff --git a/gap/grahom.gi b/gap/grahom.gi index f1196712e..b09df21d4 100644 --- a/gap/grahom.gi +++ b/gap/grahom.gi @@ -97,8 +97,7 @@ InstallMethod(DigraphColouring, "for a digraph and an integer", function(D, n) if n < 0 then ErrorNoReturn("the 2nd argument must be a non-negative integer,"); - fi; - if HasDigraphGreedyColouring(D) then + elif HasDigraphGreedyColouring(D) then if DigraphGreedyColouring(D) = fail then return fail; elif RankOfTransformation(DigraphGreedyColouring(D), diff --git a/gap/grape.gi b/gap/grape.gi index 2a10a286e..d4ec6f22d 100644 --- a/gap/grape.gi +++ b/gap/grape.gi @@ -188,9 +188,7 @@ function(G, edges, n) ErrorNoReturn("the 3rd argument must be a non-negative integer,"); elif n = 0 then return EmptyDigraph(0); - fi; - - if IsPosInt(edges[1]) then # E consists of a single edge + elif IsPosInt(edges[1]) then # E consists of a single edge edges := [edges]; fi; diff --git a/gap/io.gi b/gap/io.gi index 85834ee57..eb860f204 100644 --- a/gap/io.gi +++ b/gap/io.gi @@ -36,8 +36,7 @@ function(string, substring) if Length(string) = 0 then return []; - fi; - if Length(substring) = 1 then + elif Length(substring) = 1 then return SplitString(string, substring); fi; @@ -104,8 +103,7 @@ function(file, D) g := DigraphGroup(D); if IsTrivial(g) then TryNextMethod(); - fi; - if IO_Write(file, "DIGG") = fail then + elif IO_Write(file, "DIGG") = fail then return IO_Error; fi; out := [GeneratorsOfGroup(g), @@ -499,9 +497,7 @@ function(arg) ErrorNoReturn("the argument must be a function or fail,"); elif not mode in ["a", "w"] then ErrorNoReturn("the argument must be \"a\" or \"w\","); - fi; - - if IsString(name) and not IsExistingFile(name) then + elif IsString(name) and not IsExistingFile(name) then mode := "w"; fi; diff --git a/gap/isomorph.gi b/gap/isomorph.gi index 75cf6343c..2597e87da 100644 --- a/gap/isomorph.gi +++ b/gap/isomorph.gi @@ -410,9 +410,7 @@ function(C, D, c1, c2) od; if not ForAll(class_sizes, x -> x = 0) then return false; - fi; - - if IsMultiDigraph(C) then + elif IsMultiDigraph(C) then act := OnMultiDigraphs; else act := OnDigraphs; @@ -443,9 +441,7 @@ function(C, D) return [label1[1] / label2[1], label1[2] / label2[2]]; elif C = D then return (); - fi; - - if HasBlissCanonicalLabelling(C) and HasBlissCanonicalLabelling(D) + elif HasBlissCanonicalLabelling(C) and HasBlissCanonicalLabelling(D) or not ((HasNautyCanonicalLabelling(C) and NautyCanonicalLabelling(C) <> fail) or (HasNautyCanonicalLabelling(D) @@ -491,9 +487,7 @@ function(C, D, c1, c2) od; if not ForAll(class_sizes, x -> x = 0) then return fail; - fi; - - if DIGRAPHS_UsingBliss or IsMultiDigraph(C) then + elif DIGRAPHS_UsingBliss or IsMultiDigraph(C) then label1 := BlissCanonicalLabelling(C, colour1); label2 := BlissCanonicalLabelling(D, colour2); else diff --git a/gap/oper.gi b/gap/oper.gi index 4d7e7057c..3d268ed92 100644 --- a/gap/oper.gi +++ b/gap/oper.gi @@ -838,9 +838,7 @@ InstallMethod(OnMultiDigraphs, "for a digraph and perm coll", function(D, perms) if Length(perms) <> 2 then ErrorNoReturn("the 2nd argument must be a pair of permutations,"); - fi; - - if ForAny([1 .. DigraphNrEdges(D)], + elif ForAny([1 .. DigraphNrEdges(D)], i -> i ^ perms[2] > DigraphNrEdges(D)) then ErrorNoReturn("the 2nd entry of the 2nd argument must ", "permute the edges of the digraph that is the 1st ", @@ -1730,9 +1728,7 @@ function(D, v) if IsBound(layers[v]) then return layers[v]; - fi; - - if HasDigraphGroup(D) then + elif HasDigraphGroup(D) then gens := GeneratorsOfGroup(DigraphGroup(D)); sch := DigraphSchreierVector(D); trace := DIGRAPHS_TraceSchreierVector(gens, sch, v); @@ -1853,9 +1849,7 @@ function(D, list) if Length(list) <> 2 then ErrorNoReturn("the 2nd argument must be a list of length 2,"); - fi; - - if list[1] > DigraphNrVertices(D) or + elif list[1] > DigraphNrVertices(D) or list[2] > DigraphNrVertices(D) then ErrorNoReturn("the 2nd argument must consist of vertices of ", "the 1st argument ,"); diff --git a/gap/utils.gi b/gap/utils.gi index b73f79a3c..dc2d0aa91 100644 --- a/gap/utils.gi +++ b/gap/utils.gi @@ -600,8 +600,7 @@ function(arg) Error("expected a string or a list as the 1st argument"); elif IsList(arg[1]) and not ForAll(arg[1], IsString) then Error("expected a list of strings as the 1st argument"); - fi; - if IsList(arg[1]) then + elif IsList(arg[1]) then arg[1] := Concatenation(arg[1]); fi; msg := CallFuncList(StringFormatted, arg);