Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Flake8 violations in Python API #5332

Merged
merged 4 commits into from
Jun 16, 2021

Conversation

orsinium
Copy link
Contributor

@orsinium orsinium commented Jun 5, 2021

This PR fixes most of the flake8 violations in Python API, except autogenerated files, so the following command passes:

flake8 --max-line-length=123 --ignore=F403,F405 z3/z3{,num,poly,printer,rcf,types,util}.py

@@ -1188,11 +1188,11 @@ def _coerce_exprs(a, b, ctx=None):
return (a, b)


def _reduce(f, l, a):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

z3/z3.py:1191:16: E741 ambiguous variable name 'l

@@ -5486,9 +5486,6 @@ def __init__(self, models=True, unsat_cores=False, proofs=False, ctx=None, goal=
self.goal = Z3_mk_goal(self.ctx.ref(), models, unsat_cores, proofs)
Z3_goal_inc_ref(self.ctx.ref(), self.goal)

def __deepcopy__(self, memo={}):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

z3/z3.py:5730:5: F811 redefinition of unused '__deepcopy__' from line 5489

@@ -5834,7 +5828,13 @@ def __getitem__(self, i):
return _to_ast_ref(Z3_ast_vector_get(self.ctx.ref(), self.vector, i), self.ctx)

elif isinstance(i, slice):
return [_to_ast_ref(Z3_ast_vector_get(self.ctx.ref(), self.vector, ii), self.ctx) for ii in range(*i.indices(self.__len__()))]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

z3/z3.py:5837:124: E501 line too long (138 > 123 characters

@@ -5793,9 +5790,6 @@ def __init__(self, v=None, ctx=None):
self.ctx = ctx
Z3_ast_vector_inc_ref(self.ctx.ref(), self.vector)

def __deepcopy__(self, memo={}):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

z3/z3.py:5922:5: F811 redefinition of unused '__deepcopy__' from line 5796

@@ -6179,9 +6179,6 @@ def __init__(self, f, ctx):
if self.f is not None:
Z3_func_interp_inc_ref(self.ctx.ref(), self.f)

def __deepcopy__(self, memo={}):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

z3/z3.py:6270:5: F811 redefinition of unused '__deepcopy__' from line 6182

@@ -9130,12 +9127,14 @@ def set_default_rounding_mode(rm, ctx=None):
if is_fprm_value(rm):
_dflt_rounding_mode = rm.decl().kind()
else:
_z3_assert(_dflt_rounding_mode == Z3_OP_FPA_RM_TOWARD_ZERO or
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

z3/z3.py:9133:68: W504 line break after binary operator
z3/z3.py:9134:72: W504 line break after binary operator
z3/z3.py:9135:72: W504 line break after binary operator
z3/z3.py:9136:77: W504 line break after binary operator

@@ -9564,10 +9563,11 @@ class FPNumRef(FPRef):
"""

def sign(self):
l = (ctypes.c_int)()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

z3/z3.py:9567:9: E741 ambiguous variable name 'l'

@@ -9564,10 +9563,11 @@ class FPNumRef(FPRef):
"""

def sign(self):
l = (ctypes.c_int)()
if Z3_fpa_get_numeral_sign(self.ctx.ref(), self.as_ast(), byref(l)) == False:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

z3/z3.py:9568:77: E712 comparison to False should be 'if cond is False:' or 'if not cond:'

@@ -10709,14 +10709,6 @@ def SubSeq(s, offset, length):
return Extract(s, offset, length)


def Strings(names, ctx=None):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

z3/z3.py:10712:1: F811 redefinition of unused 'Strings' from line 10694

Both implementations are the same but the first is in a better place and the second has a better docstring. So, I took docstring from the second, moved it into the first, and removed the second.

@@ -10820,17 +10812,15 @@ def Replace(s, src, dst):
return SeqRef(Z3_mk_seq_replace(src.ctx_ref(), s.as_ast(), src.as_ast(), dst.as_ast()), s.ctx)


def IndexOf(s, substr):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

z3/z3.py:10827:1: F811 redefinition of unused 'IndexOf' from line 10823

@@ -11124,7 +11114,6 @@ def user_prop_pop(ctx, num_scopes):


def user_prop_fresh(id, ctx):
prop = _prop_closures.get(id)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

z3/z3.py:11127:5: F841 local variable 'prop' is assigned to but never used

@@ -12,7 +12,6 @@
from .z3 import *
from .z3core import *
from .z3printer import *
from fractions import Fraction
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

z3/z3rcf.py:15:1: F401 'fractions.Fraction' imported but unused

@@ -243,7 +243,7 @@ def _f():
emsg = "{}\n{}".format(assume, emsg)
return emsg

assert is_proved == False, _f()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

z3/z3util.py:246:30: E712 comparison to False should be 'if cond is False:' or 'if not cond:'

@@ -261,7 +261,7 @@ def _f():
if models is None: # unknown
print("E: cannot solve !")
return None, None
elif models == False: # unsat
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

z3/z3util.py:264:17: E712 comparison to False should be 'if cond is False:' or 'if not cond:'

@@ -446,9 +446,9 @@ def myBinOp(op, *L):
L = L[0]

if z3_debug():
assert all(not isinstance(l, bool) for l in L)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

z3/z3util.py:449:48: E741 ambiguous variable name 'l'

And it is actually confusing, I had hard times trying to visually find where is l and where is L

@@ -37,38 +37,111 @@ def _z3_assert(cond, msg):

# Z3 operator names to Z3Py
_z3_op_to_str = {
Z3_OP_TRUE: "True", Z3_OP_FALSE: "False", Z3_OP_EQ: "==", Z3_OP_DISTINCT: "Distinct",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here and everywhere below where I didn't left a comment, E501 line too long

@NikolajBjorner NikolajBjorner merged commit 589f99e into Z3Prover:master Jun 16, 2021
@orsinium
Copy link
Contributor Author

Thank you!

@orsinium orsinium deleted the flake8-123 branch June 17, 2021 07:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants