Skip to content

Commit 128ae01

Browse files
committed
Remove unused imports, use lower case to start exception message
1 parent e042933 commit 128ae01

2 files changed

Lines changed: 37 additions & 41 deletions

File tree

src/flint/types/fmpq_mpoly.pyx

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from flint.flint_base.flint_base cimport (
22
flint_mpoly,
33
flint_mpoly_context,
4-
Ordering,
54
ordering_py_to_c,
65
ordering_c_to_py,
76
)
@@ -17,7 +16,6 @@ from flint.types.fmpz cimport fmpz, any_as_fmpz
1716
from flint.types.fmpz_mpoly cimport fmpz_mpoly
1817

1918
from flint.flintlib.fmpq cimport fmpq_set, fmpq_one
20-
from flint.flintlib.mpoly cimport ordering_t
2119
from flint.flintlib.fmpq_mpoly cimport (
2220
fmpq_mpoly_add,
2321
fmpq_mpoly_add_fmpq,
@@ -54,7 +52,6 @@ from flint.flintlib.fmpq_mpoly cimport (
5452
fmpq_mpoly_set_coeff_fmpq_fmpz,
5553
fmpq_mpoly_set_fmpq,
5654
fmpq_mpoly_set_str_pretty,
57-
fmpq_mpoly_set_term_coeff_fmpq,
5855
fmpq_mpoly_sort_terms,
5956
fmpq_mpoly_sqrt,
6057
fmpq_mpoly_sub,
@@ -163,16 +160,16 @@ cdef class fmpq_mpoly_ctx(flint_mpoly_context):
163160
fmpq_mpoly res
164161

165162
if not isinstance(d, dict):
166-
raise ValueError("Expected a dictionary")
163+
raise ValueError("expected a dictionary")
167164

168165
res = create_fmpq_mpoly(self)
169166

170167
for k, v in d.items():
171168
o = any_as_fmpq(v)
172169
if o is NotImplemented:
173-
raise TypeError(f"Cannot coerce coefficient '{v}' to fmpq")
170+
raise TypeError(f"cannot coerce coefficient '{v}' to fmpq")
174171
elif len(k) != nvars:
175-
raise ValueError(f"Expected {nvars} exponents, got {len(k)}")
172+
raise ValueError(f"expected {nvars} exponents, got {len(k)}")
176173

177174
exp_vec = fmpz_vec(k)
178175

@@ -212,33 +209,34 @@ cdef class fmpq_mpoly(flint_mpoly):
212209
raise TypeError(f"{ctx} is not a fmpq_mpoly_ctx or fmpz_mpoly_ctx")
213210
elif ctx.nvars() != val.context().nvars():
214211
raise ValueError(
215-
f"Provided context ('{ctx}') and provided fmpz_mpoly ('{val}') don't share the same number of variables"
212+
f"Provided context ('{ctx}') and provided fmpz_mpoly ('{val}') don't share the same number of "
213+
"variables"
216214
)
217215
init_fmpq_mpoly(self, ctx)
218216
fmpz_mpoly_set(self.val.zpoly, (<fmpz_mpoly>val).val, (<fmpz_mpoly> val).ctx.val)
219217
fmpq_one(self.val.content)
220218
fmpq_mpoly_reduce(self.val, self.ctx.val)
221219
elif isinstance(val, dict):
222220
if ctx is None:
223-
raise ValueError("A context is required to create a fmpq_mpoly from a dict")
221+
raise ValueError("a context is required to create a fmpq_mpoly from a dict")
224222
x = ctx.from_dict(val)
225223
# XXX: this copy is silly, have a ctx function that assigns an fmpz_mpoly_t
226224
init_fmpq_mpoly(self, ctx)
227225
fmpq_mpoly_set(self.val, (<fmpq_mpoly>x).val, self.ctx.val)
228226
elif isinstance(val, str):
229227
if ctx is None:
230-
raise ValueError("Cannot parse a polynomial without context")
228+
raise ValueError("cannot parse a polynomial without context")
231229
val = val.encode("ascii")
232230
init_fmpq_mpoly(self, ctx)
233231
if fmpq_mpoly_set_str_pretty(self.val, val, self.ctx.c_names, self.ctx.val) == -1:
234-
raise ValueError("Unable to parse fmpq_mpoly from string")
232+
raise ValueError("unable to parse fmpq_mpoly from string")
235233
fmpq_mpoly_sort_terms(self.val, self.ctx.val)
236234
else:
237235
v = any_as_fmpq(val)
238236
if v is NotImplemented:
239237
raise TypeError("cannot create fmpz_mpoly from type %s" % type(val))
240238
if ctx is None:
241-
raise ValueError("Need context to convert fmpz to fmpq_mpoly")
239+
raise ValueError("need context to convert fmpz to fmpq_mpoly")
242240
init_fmpq_mpoly(self, ctx)
243241
fmpq_mpoly_set_fmpq(self.val, (<fmpq>v).val, self.ctx.val)
244242

@@ -280,9 +278,9 @@ cdef class fmpq_mpoly(flint_mpoly):
280278
slong nvars = self.ctx.nvars()
281279

282280
if not isinstance(x, tuple):
283-
raise TypeError("Exponent vector index is not a tuple")
281+
raise TypeError("exponent vector index is not a tuple")
284282
elif len(x) != nvars:
285-
raise ValueError("Exponent vector provided does not match number of variables")
283+
raise ValueError("exponent vector provided does not match number of variables")
286284

287285
res = fmpq()
288286
exp_vec = fmpz_vec(x, double_indirect=True)
@@ -308,11 +306,11 @@ cdef class fmpq_mpoly(flint_mpoly):
308306

309307
coeff = any_as_fmpq(y)
310308
if coeff is NotImplemented:
311-
raise TypeError("Provided coefficient not coercible to fmpq")
309+
raise TypeError("provided coefficient not coercible to fmpq")
312310
elif not isinstance(x, tuple):
313-
raise TypeError("Exponent vector index is not a tuple")
311+
raise TypeError("exponent vector index is not a tuple")
314312
elif len(x) != nvars:
315-
raise ValueError("Exponent vector provided does not match number of variables")
313+
raise ValueError("exponent vector provided does not match number of variables")
316314

317315
exp_vec = fmpz_vec(x, double_indirect=True)
318316
fmpq_mpoly_set_coeff_fmpq_fmpz(self.val, (<fmpq>coeff).val, exp_vec.double_indirect, self.ctx.val)
@@ -530,19 +528,19 @@ cdef class fmpq_mpoly(flint_mpoly):
530528
slong nvars = self.ctx.nvars(), nargs = len(args)
531529

532530
if nargs < nvars:
533-
raise ValueError("Not enough arguments provided")
531+
raise ValueError("not enough arguments provided")
534532
elif nargs > nvars:
535-
raise ValueError("More arguments provided than variables")
533+
raise ValueError("more arguments provided than variables")
536534

537535
args_fmpq = tuple(any_as_fmpq(v) for v in args)
538536
for arg in args_fmpq:
539537
if arg is NotImplemented:
540-
raise TypeError(f"Cannot coerce argument ('{arg}') to fmpq")
538+
raise TypeError(f"cannot coerce argument ('{arg}') to fmpq")
541539

542540
V = fmpq_vec(args_fmpq, double_indirect=True)
543541
vres = fmpq.__new__(fmpq)
544542
if fmpq_mpoly_evaluate_all_fmpq(vres.val, self.val, V.double_indirect, self.ctx.val) == 0:
545-
raise ValueError("Unreasonably large polynomial") # pragma: no cover
543+
raise ValueError("unreasonably large polynomial") # pragma: no cover
546544
return vres
547545

548546
def monoms(self):
@@ -676,20 +674,20 @@ cdef class fmpq_mpoly(flint_mpoly):
676674
slong i, nvars = self.ctx.nvars(), nargs = len(args)
677675

678676
if nargs < nvars:
679-
raise ValueError("Not enough arguments provided")
677+
raise ValueError("not enough arguments provided")
680678
elif nargs > nvars:
681-
raise ValueError("More arguments provided than variables")
679+
raise ValueError("more arguments provided than variables")
682680
elif not all(typecheck(arg, fmpq_mpoly) for arg in args):
683-
raise TypeError("All arguments must be fmpq_mpolys")
681+
raise TypeError("all arguments must be fmpq_mpolys")
684682

685683
res_ctx = (<fmpq_mpoly> args[0]).ctx
686684
if not all((<fmpq_mpoly> args[i]).ctx is res_ctx for i in range(1, len(args))):
687-
raise IncompatibleContextError("All arguments must share the same context")
685+
raise IncompatibleContextError("all arguments must share the same context")
688686

689687
C = fmpq_mpoly_vec(args, res_ctx, double_indirect=True)
690688
res = create_fmpq_mpoly(res_ctx)
691689
if fmpq_mpoly_compose_fmpq_mpoly(res.val, self.val, C.double_indirect, self.ctx.val, res_ctx.val) == 0:
692-
raise ValueError("Unreasonably large polynomial") # pragma: no cover
690+
raise ValueError("unreasonably large polynomial") # pragma: no cover
693691
return res
694692

695693
def context(self):

src/flint/types/fmpz_mpoly.pyx

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from flint.flint_base.flint_base cimport (
22
flint_mpoly,
33
flint_mpoly_context,
4-
Ordering,
54
ordering_py_to_c,
65
ordering_c_to_py,
76
)
@@ -48,7 +47,6 @@ from flint.flintlib.fmpz_mpoly cimport (
4847
fmpz_mpoly_set_coeff_fmpz_fmpz,
4948
fmpz_mpoly_set_fmpz,
5049
fmpz_mpoly_set_str_pretty,
51-
fmpz_mpoly_set_term_coeff_fmpz,
5250
fmpz_mpoly_sort_terms,
5351
fmpz_mpoly_sqrt_heap,
5452
fmpz_mpoly_sub,
@@ -200,25 +198,25 @@ cdef class fmpz_mpoly(flint_mpoly):
200198
raise IncompatibleContextError(f"{ctx} is not {(<fmpz_mpoly>val).ctx}")
201199
elif isinstance(val, dict):
202200
if ctx is None:
203-
raise ValueError("A context is required to create a fmpz_mpoly from a dict")
201+
raise ValueError("a context is required to create a fmpz_mpoly from a dict")
204202
x = ctx.from_dict(val)
205203
# XXX: this copy is silly, have a ctx function that assigns an fmpz_mpoly_t
206204
init_fmpz_mpoly(self, ctx)
207205
fmpz_mpoly_set(self.val, (<fmpz_mpoly>x).val, self.ctx.val)
208206
elif isinstance(val, str):
209207
if ctx is None:
210-
raise ValueError("Cannot parse a polynomial without context")
208+
raise ValueError("cannot parse a polynomial without context")
211209
val = bytes(val, 'utf-8')
212210
init_fmpz_mpoly(self, ctx)
213211
if fmpz_mpoly_set_str_pretty(self.val, val, self.ctx.c_names, self.ctx.val) == -1:
214-
raise ValueError("Unable to parse fmpz_mpoly from string")
212+
raise ValueError("unable to parse fmpz_mpoly from string")
215213
fmpz_mpoly_sort_terms(self.val, self.ctx.val)
216214
else:
217215
v = any_as_fmpz(val)
218216
if v is NotImplemented:
219-
raise TypeError("Cannot create fmpz_mpoly from type %s" % type(val))
217+
raise TypeError("cannot create fmpz_mpoly from type %s" % type(val))
220218
if ctx is None:
221-
raise ValueError("Need context to convert fmpz to fmpz_mpoly")
219+
raise ValueError("need context to convert fmpz to fmpz_mpoly")
222220
init_fmpz_mpoly(self, ctx)
223221
fmpz_mpoly_set_fmpz(self.val, (<fmpz>v).val, self.ctx.val)
224222

@@ -512,19 +510,19 @@ cdef class fmpz_mpoly(flint_mpoly):
512510
slong nvars = self.ctx.nvars(), nargs = len(args)
513511

514512
if nargs < nvars:
515-
raise ValueError("Not enough arguments provided")
513+
raise ValueError("not enough arguments provided")
516514
elif nargs > nvars:
517-
raise ValueError("More arguments provided than variables")
515+
raise ValueError("more arguments provided than variables")
518516

519517
args_fmpz = tuple(any_as_fmpz(v) for v in args)
520518
for arg in args_fmpz:
521519
if arg is NotImplemented:
522-
raise TypeError(f"Cannot coerce argument ('{arg}') to fmpz")
520+
raise TypeError(f"cannot coerce argument ('{arg}') to fmpz")
523521

524522
V = fmpz_vec(args_fmpz, double_indirect=True)
525523
vres = fmpz.__new__(fmpz)
526524
if fmpz_mpoly_evaluate_all_fmpz(vres.val, self.val, V.double_indirect, self.ctx.val) == 0:
527-
raise ValueError("Unreasonably large polynomial") # pragma: no cover
525+
raise ValueError("unreasonably large polynomial") # pragma: no cover
528526
return vres
529527

530528
def monoms(self):
@@ -658,20 +656,20 @@ cdef class fmpz_mpoly(flint_mpoly):
658656
slong i, nvars = self.ctx.nvars(), nargs = len(args)
659657

660658
if nargs < nvars:
661-
raise ValueError("Not enough arguments provided")
659+
raise ValueError("not enough arguments provided")
662660
elif nargs > nvars:
663-
raise ValueError("More arguments provided than variables")
661+
raise ValueError("more arguments provided than variables")
664662
elif not all(typecheck(arg, fmpz_mpoly) for arg in args):
665-
raise TypeError("All arguments must be fmpz_mpolys")
663+
raise TypeError("all arguments must be fmpz_mpolys")
666664

667665
res_ctx = (<fmpz_mpoly> args[0]).ctx
668666
if not all((<fmpz_mpoly> args[i]).ctx is res_ctx for i in range(1, len(args))):
669-
raise IncompatibleContextError("All arguments must share the same context")
667+
raise IncompatibleContextError("all arguments must share the same context")
670668

671669
C = fmpz_mpoly_vec(args, res_ctx, double_indirect=True)
672670
res = create_fmpz_mpoly(res_ctx)
673671
if fmpz_mpoly_compose_fmpz_mpoly(res.val, self.val, C.double_indirect, self.ctx.val, res_ctx.val) == 0:
674-
raise ValueError("Unreasonably large polynomial") # pragma: no cover
672+
raise ValueError("unreasonably large polynomial") # pragma: no cover
675673
return res
676674

677675
def context(self):

0 commit comments

Comments
 (0)