Skip to content

Commit

Permalink
fix and activate E714 in the linter (#99)
Browse files Browse the repository at this point in the history
  • Loading branch information
fchapoton authored Apr 14, 2023
1 parent 76a6c14 commit 0d47c24
Show file tree
Hide file tree
Showing 14 changed files with 34 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Run pycodestyle
shell: bash -l {0}
# We currently only check for some warnings. We should enable & fix more of them.
run: pycodestyle --select=E111,E21,E221,E222,E225,E227,E228,E241,E251,E262,E265,E271,E272,E30,E401,E701,E702,E703,E704,E711,E713,E721,W2,W3,W6 python/
run: pycodestyle --select=E111,E21,E221,E222,E225,E227,E228,E241,E251,E262,E265,E271,E272,E30,E401,E701,E702,E703,E704,E711,E713,E714,E721,W2,W3,W6 python/

env:
MAKEFLAGS: -j2
2 changes: 1 addition & 1 deletion python/ptolemy/coordinates.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def __init__(self, d, is_numerical=True, py_eval_section=None,
non_trivial_generalized_obstruction_class)
processed_dict = d

if not py_eval_section is None:
if py_eval_section is not None:
# process the extra information that is given by
# ptolemyVariety's py_eval_section

Expand Down
4 changes: 2 additions & 2 deletions python/ptolemy/matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def _get_only_non_zero_entry_in_col(m, col):
assert (entry is None), (
"more than one non-zero entry in column %d" % col)
entry = row[col]
if not entry is None:
if entry is not None:
return entry
return 0

Expand All @@ -222,7 +222,7 @@ def _get_only_non_zero_entry_in_row(m, row):
assert (entry is None), (
"more than one non-zero entry in row %d" % row)
entry = i
if not entry is None:
if entry is not None:
return entry
return 0

Expand Down
4 changes: 2 additions & 2 deletions python/ptolemy/numericalSolutionsToGroebnerBasis.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def _get_first(l):


def _remove(l, element):
return [x for x in l if not x is element]
return [x for x in l if x is not element]


def _numerical_solutions_recursion(polysAndVars, solutionDict):
Expand All @@ -92,7 +92,7 @@ def _numerical_solutions_recursion(polysAndVars, solutionDict):
for poly in polysAndVars
if poly.get_variable_if_univariate() ])

if not univariatePoly is None:
if univariatePoly is not None:
variable = univariatePoly.get_variable_if_univariate()
variableDicts = [ ]

Expand Down
2 changes: 1 addition & 1 deletion python/ptolemy/polynomial.py
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@ def process_next_token(s):

# parse constants or variables and push them onto the operand stack
constant, rest = parse_coefficient_function(s)
if not constant is None:
if constant is not None:
operand_stack.append(Polynomial.constant_polynomial(constant))
no_operand_since_opening_parenthesis[0] = False
return rest
Expand Down
4 changes: 2 additions & 2 deletions python/ptolemy/ptolemyGeneralizedObstructionClass.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ def __init__(self, H2_class, index=None, N=None, manifold=None):
self._manifold = manifold

def _checkManifoldAndN(self, manifold, N):
if not self._manifold is None:
if self._manifold is not None:
assert manifold == self._manifold, (
"PtolemyGeneralizedObstructionClass for wrong manifold")

if not self._N is None:
if self._N is not None:
assert N == self._N, (
"PtolemyGeneralizedObstructionClass for wrong N")

Expand Down
2 changes: 1 addition & 1 deletion python/ptolemy/ptolemyVariety.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ def filename_base(self):

if self._obstruction_class is None:
obstruction_class = "0"
elif not self._obstruction_class._index is None:
elif self._obstruction_class._index is not None:
obstruction_class = "%d" % self._obstruction_class._index
# filenames which contain regex special characters cause
# trouble with PyInstaller's globbing module.
Expand Down
9 changes: 4 additions & 5 deletions python/ptolemy/solutionsToPrimeIdealGroebnerBasis.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,18 +101,17 @@ def _remove(l, element):
'''
Returns a copy of list without element.
'''
return [x for x in l if not x is element]
return [x for x in l if x is not element]


def extensions_and_assignments(polys):
'''
Splits into extensions and assignments s in example given above
in _exact_solutions.
'''

extensions = [ ] # extension polynomials
extension_vars = [ ]
assignments = { } # pure assignments
extensions = [] # extension polynomials
extension_vars = []
assignments = {} # pure assignments

# Iterate while polys left
while polys:
Expand Down
4 changes: 2 additions & 2 deletions python/ptolemy/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def testSolutionsForManifold(M, N, solutions, baseline_cvolumes=None,

# check we encountered non-zero dimensional component if that's
# expected
if not expect_non_zero_dimensional is None:
if expect_non_zero_dimensional is not None:
assert expect_non_zero_dimensional == found_non_zero_dimensional

# check the numerical solutions against the manifold
Expand Down Expand Up @@ -199,7 +199,7 @@ def testSolutionsForManifold(M, N, solutions, baseline_cvolumes=None,
abs(geom_vol - vol) < 1e-11 for vol in volumes]

# check that complex volumes match baseline volumes
if not baseline_cvolumes is None:
if baseline_cvolumes is not None:
check_volumes(complex_volumes, baseline_cvolumes)

pari.set_real_precision(old_precision)
Expand Down
4 changes: 2 additions & 2 deletions python/raytracing/gui_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def __init__(self, uniform_dict, key,
raise Exception("int/float uniform does not support index")
elif self.uniform_type == 'float[]':
self.scalar_type = 'float'
if index is None or not component_index is None:
if index is None or component_index is not None:
raise Exception("Need to specify index for float[] uniform")
elif self.uniform_type == 'vec2[]':
self.scalar_type = 'float'
Expand All @@ -93,7 +93,7 @@ def __init__(self, uniform_dict, key,
raise Exception("int/float uniform does not support index")
elif self.uniform_type == 'bool[]':
self.scalar_type = 'bool'
if index is None or not component_index is None:
if index is None or component_index is not None:
raise Exception("Need to specify index for bool[] uniform")
else:
raise Exception("Unsupported uniform type %s" % self.uniform_type)
Expand Down
2 changes: 1 addition & 1 deletion python/raytracing/hyperboloid_navigation.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ def process_key_events_and_redraw(self):
last_and_release[0] = t

# If there is key press time we need to account for
if not dT is None:
if dT is not None:
RF = m.base_ring()
# Compute effect on view matrix
m = m * self.keymapping[k](
Expand Down
4 changes: 2 additions & 2 deletions python/raytracing/hyperboloid_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,10 @@ def _orthonormalize_row(row, other_rows, row_sign):

def _orthonormalize_row_sane(row, fallback_value, other_rows, sign):
r = _orthonormalize_row(row, other_rows, sign)
if not r is None:
if r is not None:
return r
r = _orthonormalize_row(fallback_value, other_rows, sign)
if not r is None:
if r is not None:
return r
return fallback_value

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ def unglued_generators_and_vertices_for_tile(self, tile):
other_m = tile.matrix * gen_m
other_tile = self.find_tile(other_m)
if other_tile:
if not tile is other_tile:
if tile is not other_tile:
for (corner, other_corner), perm in self.mcomplex.Generators[g]:
for v in simplex.VerticesOfFaceCounterclockwise[corner.Subsimplex]:
vertex = corner.Tetrahedron.Class[v]
Expand Down
25 changes: 12 additions & 13 deletions python/verify/squareExtensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ def __init__(self, value=None, d={}, embed_cache=None):
#
# { r_1 : c_1, r_2 : c_2, ..., r_n : c_n }

if not value is None:
if value is not None:
if d:
raise TypeError("SqrtLinCombination has both value and "
"dictionary.")
Expand Down Expand Up @@ -333,7 +333,7 @@ def inverse(self):
# The inverse element of c_1 * sqrt(r_1)
# is (1 / (c_1 * r_1)) * sqrt(r_1)
l = len(self._dict)
if not l == 1:
if l != 1:
# Do not implement other elements.
if l == 0:
# In particular, do not invert 0
Expand Down Expand Up @@ -383,7 +383,7 @@ def sqrt(self):
# Iterate through only term
for k, v in self._dict.items():
# Make sure expression in sqrt is 1
if not k == 1:
if k != 1:
raise TypeError('SqrtLinCombination sqrt not fully '
'implemented')
return SqrtLinCombination(
Expand Down Expand Up @@ -475,7 +475,7 @@ def sign_with_interval(self):
# be slow so we try numerically first.
prec = 106
numerical_sign, interval_val = self._sign_numerical(prec)
if not numerical_sign is None:
if numerical_sign is not None:
# We could determine the sign using interval arithmetics
# Return the result.
return numerical_sign, interval_val
Expand All @@ -490,7 +490,7 @@ def sign_with_interval(self):
while True:
prec *= 2
numerical_sign, interval_val = self._sign_numerical(prec)
if not numerical_sign is None:
if numerical_sign is not None:
return numerical_sign, interval_val

def sign(self):
Expand Down Expand Up @@ -794,7 +794,7 @@ def is_zero(self):
while True:
# Determine signs, None indicates the signs couldn't be certified
opposite_signs = _opposite_signs(left, right, prec)
if not opposite_signs is None:
if opposite_signs is not None:
# Done
return opposite_signs

Expand Down Expand Up @@ -864,8 +864,7 @@ def _filter_zero(d):
"""
Given a dict, filter out all items where the value is 0.
"""

return dict( (k, v) for k, v in d.items() if not v == 0)
return dict((k, v) for k, v in d.items() if v != 0)


def _convert_to_allowed_type(number):
Expand Down Expand Up @@ -900,7 +899,7 @@ def _get_embed_cache(l1, l2):
for l in [l1, l2]:
if ((isinstance(l, SqrtLinCombination) or
isinstance(l, _FactorizedSqrtLinCombination)) and
not l._embed_cache is None):
l._embed_cache is not None):
return l._embed_cache

return None
Expand Down Expand Up @@ -932,27 +931,27 @@ def _get_interval_embedding_from_cache(nf, RIF, cache):
# print("Warning: No cache used")

# The key 'gen_embedding' holds the value of nf.gen_embedding()
if (not cache is None) and 'gen_embedding' in cache:
if cache is not None and 'gen_embedding' in cache:
# We can read it from cache
gen_embedding = cache['gen_embedding']
else:
# We need to evaluate it
gen_embedding = nf.gen_embedding()
if (not cache is None):
if cache is not None:
# Save in cache for future use
cache['gen_embedding'] = gen_embedding

# Get the desired precision of the RealIntervalField
prec = RIF.prec()
# The precision (which is an int) is the key into the cache
if (not cache is None) and prec in cache:
if cache is not None and prec in cache:
# RIF(nf.gen_embedding()) is in the cache
# We can just return the result
return cache[prec]

# We need to actually compute it.
interval = RIF(gen_embedding)
if not cache is None:
if cache is not None:
# Save in cache for future use.
cache[prec] = interval

Expand Down

0 comments on commit 0d47c24

Please sign in to comment.