Skip to content

Commit 3d18e35

Browse files
authored
Merge pull request #11 from jepler/update-black-ci-etc
Upgrade pylint, black
2 parents 2aeae70 + 7f0d437 commit 3d18e35

File tree

4 files changed

+57
-53
lines changed

4 files changed

+57
-53
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ jobs:
4242
# (e.g. - apt-get: gettext, etc; pip: circuitpython-build-tools, requirements.txt; etc.)
4343
run: |
4444
source actions-ci/install.sh
45-
- name: Pip install pylint, Sphinx, pre-commit
45+
- name: Pip install Sphinx, pre-commit
4646
run: |
47-
pip install --force-reinstall pylint Sphinx sphinx-rtd-theme pre-commit sphinx-autoapi
47+
pip install --force-reinstall Sphinx sphinx-rtd-theme pre-commit sphinx-autoapi
4848
- name: Library version
4949
run: git describe --dirty --always --tags
5050
- name: Setup problem matchers

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
repos:
66
- repo: https://github.com/python/black
7-
rev: 19.10b0
7+
rev: 22.1.0
88
hooks:
99
- id: black
1010
- repo: https://github.com/fsfe/reuse-tool
@@ -18,7 +18,7 @@ repos:
1818
- id: end-of-file-fixer
1919
- id: trailing-whitespace
2020
- repo: https://github.com/pycqa/pylint
21-
rev: pylint-2.6.0
21+
rev: v2.12.2
2222
hooks:
2323
- id: pylint
2424
name: lint (examples)

.pylintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ confidence=
5656
# no Warning level messages displayed, use"--disable=all --enable=classes
5757
# --disable=W"
5858
# disable=import-error,print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call
59-
disable=print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call,import-error,bad-continuation
59+
disable=print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call,import-error,bad-continuation,consider-using-f-string
6060

6161
# Enable the message, report, category or checker with the given id(s). You can
6262
# either give multiple identifier separated by comma (,) or put this option

jepler_udecimal/__init__.py

Lines changed: 52 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,6 @@ def _as_integer_ratio(f):
169169
else:
170170
return m, (1 << (-e))
171171

172-
173172
else:
174173
_as_integer_ratio = float.as_integer_ratio
175174

@@ -739,7 +738,7 @@ def from_float(cls, f):
739738
sign = 1
740739
n, d = _as_integer_ratio(abs(f))
741740
k = d.bit_length() - 1
742-
coeff = str(n * 5 ** k)
741+
coeff = str(n * 5**k)
743742
else:
744743
raise TypeError("argument must be int or float.")
745744

@@ -1349,9 +1348,9 @@ def __truediv__(self, other, context=None):
13491348
op1 = _WorkRep(self)
13501349
op2 = _WorkRep(other)
13511350
if shift >= 0:
1352-
coeff, remainder = divmod(op1.int * 10 ** shift, op2.int)
1351+
coeff, remainder = divmod(op1.int * 10**shift, op2.int)
13531352
else:
1354-
coeff, remainder = divmod(op1.int, op2.int * 10 ** -shift)
1353+
coeff, remainder = divmod(op1.int, op2.int * 10**-shift)
13551354
if remainder:
13561355
# result is not exact; adjust to ensure correct rounding
13571356
if coeff % 5 == 0:
@@ -1392,7 +1391,7 @@ def _divide(self, other, context):
13921391
else:
13931392
op2.int *= 10 ** (op2.exp - op1.exp)
13941393
q, r = divmod(op1.int, op2.int)
1395-
if q < 10 ** context.prec:
1394+
if q < 10**context.prec:
13961395
return (
13971396
_dec_from_triple(sign, str(q), 0),
13981397
_dec_from_triple(self._sign, str(r), ideal_exp),
@@ -1552,7 +1551,7 @@ def remainder_near(self, other, context=None):
15521551
r -= op2.int
15531552
q += 1
15541553

1555-
if q >= 10 ** context.prec:
1554+
if q >= 10**context.prec:
15561555
return context._raise_error(DivisionImpossible)
15571556

15581557
# result has same sign as self unless r is negative
@@ -1619,7 +1618,7 @@ def __int__(self):
16191618
raise OverflowError("Cannot convert infinity to integer")
16201619
s = (-1) ** self._sign
16211620
if self._exp >= 0:
1622-
return s * int(self._int) * 10 ** self._exp
1621+
return s * int(self._int) * 10**self._exp
16231622
else:
16241623
return s * int(self._int[: self._exp] or "0")
16251624

@@ -1981,7 +1980,7 @@ def _power_exact(self, other, p):
19811980
ye += 1
19821981
if ye < 0:
19831982
return None
1984-
exponent = xe * 10 ** ye
1983+
exponent = xe * 10**ye
19851984
if y.sign == 1:
19861985
exponent = -exponent
19871986
# if other is a nonnegative integer, use ideal exponent
@@ -2040,13 +2039,13 @@ def _power_exact(self, other, p):
20402039

20412040
if e > emax:
20422041
return None
2043-
xc = 5 ** e
2042+
xc = 5**e
20442043

20452044
elif last_digit == 5:
20462045
# e >= log_5(xc) if xc is a power of 5; we have
20472046
# equality all the way up to xc=5**2658
20482047
e = _nbits(xc) * 28 // 65
2049-
xc, remainder = divmod(5 ** e, xc)
2048+
xc, remainder = divmod(5**e, xc)
20502049
if remainder:
20512050
return None
20522051
while xc % 5 == 0:
@@ -2067,18 +2066,18 @@ def _power_exact(self, other, p):
20672066

20682067
if e > emax:
20692068
return None
2070-
xc = 2 ** e
2069+
xc = 2**e
20712070
else:
20722071
return None
20732072

2074-
if xc >= 10 ** p:
2073+
if xc >= 10**p:
20752074
return None
20762075
xe = -e - xe
20772076
return _dec_from_triple(0, str(xc), xe)
20782077

20792078
# now y is positive; find m and n such that y = m/n
20802079
if ye >= 0:
2081-
m, n = yc * 10 ** ye, 1
2080+
m, n = yc * 10**ye, 1
20822081
else:
20832082
if xe != 0 and len(str(abs(yc * xe))) <= -ye:
20842083
return None
@@ -2122,9 +2121,9 @@ def _power_exact(self, other, p):
21222121
# 10**p and the result is not representable.
21232122
if xc > 1 and m > p * 100 // _log10_lb(xc):
21242123
return None
2125-
xc = xc ** m
2124+
xc = xc**m
21262125
xe *= m
2127-
if xc > 10 ** p:
2126+
if xc > 10**p:
21282127
return None
21292128

21302129
# by this point the result *is* exactly representable
@@ -2569,15 +2568,15 @@ def sqrt(self, context=None):
25692568
# rescale so that c has exactly prec base 100 'digits'
25702569
shift = prec - l
25712570
if shift >= 0:
2572-
c *= 100 ** shift
2571+
c *= 100**shift
25732572
exact = True
25742573
else:
2575-
c, remainder = divmod(c, 100 ** -shift)
2574+
c, remainder = divmod(c, 100**-shift)
25762575
exact = not remainder
25772576
e -= shift
25782577

25792578
# find n = floor(sqrt(c)) using Newton's method
2580-
n = 10 ** prec
2579+
n = 10**prec
25812580
while True:
25822581
q = c // n
25832582
if n <= q:
@@ -2590,9 +2589,9 @@ def sqrt(self, context=None):
25902589
# result is exact; rescale to use ideal exponent e
25912590
if shift >= 0:
25922591
# assert n % 10**shift == 0
2593-
n //= 10 ** shift
2592+
n //= 10**shift
25942593
else:
2595-
n *= 10 ** -shift
2594+
n *= 10**-shift
25962595
e += shift
25972596
else:
25982597
# result is not exact; fix last digit as described above
@@ -2812,7 +2811,7 @@ def compare_total_mag(self, other, context=None):
28122811
return s.compare_total(o)
28132812

28142813
def copy_abs(self):
2815-
"""Returns a copy with the sign set to 0. """
2814+
"""Returns a copy with the sign set to 0."""
28162815
return _dec_from_triple(0, self._int, self._exp, self._is_special)
28172816

28182817
def copy_negate(self):
@@ -2976,11 +2975,11 @@ def _ln_exp_bound(self):
29762975
c, e = op.int, op.exp
29772976
if adj == 0:
29782977
# 1 < self < 10
2979-
num = str(c - 10 ** -e)
2978+
num = str(c - 10**-e)
29802979
den = str(c)
29812980
return len(num) - len(den) - (num < den)
29822981
# adj == -1, 0.1 <= self < 1
2983-
return e + len(str(10 ** -e - c)) - 1
2982+
return e + len(str(10**-e - c)) - 1
29842983

29852984
def ln(self, context=None):
29862985
"""Returns the natural (base e) logarithm of self."""
@@ -3054,11 +3053,11 @@ def _log10_exp_bound(self):
30543053
c, e = op.int, op.exp
30553054
if adj == 0:
30563055
# 1 < self < 10
3057-
num = str(c - 10 ** -e)
3056+
num = str(c - 10**-e)
30583057
den = str(231 * c)
30593058
return len(num) - len(den) - (num < den) + 2
30603059
# adj == -1, 0.1 <= self < 1
3061-
num = str(10 ** -e - c)
3060+
num = str(10**-e - c)
30623061
return len(num) + e - (num < "231") - 1
30633062

30643063
def log10(self, context=None):
@@ -3112,7 +3111,7 @@ def log10(self, context=None):
31123111
return ans
31133112

31143113
def logb(self, context=None):
3115-
""" Returns the exponent of the magnitude of self's MSD.
3114+
"""Returns the exponent of the magnitude of self's MSD.
31163115
31173116
The result is the integer which is the exponent of the magnitude
31183117
of the most significant digit of self (as though it were truncated
@@ -3324,8 +3323,8 @@ def _dec_from_triple(sign, coefficient, exponent, special=False):
33243323
class _ContextManager(object):
33253324
"""Context manager class to support localcontext().
33263325
3327-
Sets a copy of the supplied context in __enter__() and restores
3328-
the previous decimal context in __exit__()
3326+
Sets a copy of the supplied context in __enter__() and restores
3327+
the previous decimal context in __exit__()
33293328
"""
33303329

33313330
def __init__(self, new_context):
@@ -4202,7 +4201,7 @@ def log10(self, a):
42024201
return a.log10(context=self)
42034202

42044203
def logb(self, a):
4205-
""" Returns the exponent of the magnitude of the operand's MSD.
4204+
"""Returns the exponent of the magnitude of the operand's MSD.
42064205
42074206
The result is the integer which is the exponent of the magnitude
42084207
of the most significant digit of the operand (as though the
@@ -4902,7 +4901,7 @@ def _normalize(op1, op2, prec=0):
49024901

49034902

49044903
def _decimal_lshift_exact(n, e):
4905-
""" Given integers n and e, return n * 10**e if it's an integer, else None.
4904+
"""Given integers n and e, return n * 10**e if it's an integer, else None.
49064905
49074906
The computation is designed to avoid computing large powers of 10
49084907
unnecessarily.
@@ -4915,12 +4914,12 @@ def _decimal_lshift_exact(n, e):
49154914
if n == 0:
49164915
return 0
49174916
elif e >= 0:
4918-
return n * 10 ** e
4917+
return n * 10**e
49194918
else:
49204919
# val_n = largest power of 10 dividing n.
49214920
str_n = str(abs(n))
49224921
val_n = len(str_n) - len(str_n.rstrip("0"))
4923-
return None if val_n < -e else n // 10 ** -e
4922+
return None if val_n < -e else n // 10**-e
49244923

49254924

49264925
def _sqrt_nearest(n, a):
@@ -5023,20 +5022,20 @@ def _dlog10(c, e, p):
50235022
f = e + l - (e + l >= 1)
50245023

50255024
if p > 0:
5026-
M = 10 ** p
5025+
M = 10**p
50275026
k = e + p - f
50285027
if k >= 0:
5029-
c *= 10 ** k
5028+
c *= 10**k
50305029
else:
5031-
c = _div_nearest(c, 10 ** -k)
5030+
c = _div_nearest(c, 10**-k)
50325031

50335032
log_d = _ilog(c, M) # error < 5 + 22 = 27
50345033
log_10 = _log10_digits(p) # error < 1
50355034
log_d = _div_nearest(log_d * M, log_10)
50365035
log_tenpower = f * M # exact
50375036
else:
50385037
log_d = 0 # error < 2.31
5039-
log_tenpower = _div_nearest(f, 10 ** -p) # error < 0.5
5038+
log_tenpower = _div_nearest(f, 10**-p) # error < 0.5
50405039

50415040
return _div_nearest(log_tenpower + log_d, 100)
50425041

@@ -5060,12 +5059,12 @@ def _dlog(c, e, p):
50605059
if p > 0:
50615060
k = e + p - f
50625061
if k >= 0:
5063-
c *= 10 ** k
5062+
c *= 10**k
50645063
else:
5065-
c = _div_nearest(c, 10 ** -k) # error of <= 0.5 in c
5064+
c = _div_nearest(c, 10**-k) # error of <= 0.5 in c
50665065

50675066
# _ilog magnifies existing error in c by a factor of at most 10
5068-
log_d = _ilog(c, 10 ** p) # error < 5 + 22 = 27
5067+
log_d = _ilog(c, 10**p) # error < 5 + 22 = 27
50695068
else:
50705069
# p <= 0: just approximate the whole thing by 0; error < 2.31
50715070
log_d = 0
@@ -5076,7 +5075,7 @@ def _dlog(c, e, p):
50765075
if p + extra >= 0:
50775076
# error in f * _log10_digits(p+extra) < |f| * 1 = |f|
50785077
# after division, error < |f|/10**extra + 0.5 < 10 + 0.5 < 11
5079-
f_log_ten = _div_nearest(f * _log10_digits(p + extra), 10 ** extra)
5078+
f_log_ten = _div_nearest(f * _log10_digits(p + extra), 10**extra)
50805079
else:
50815080
f_log_ten = 0
50825081
else:
@@ -5189,16 +5188,16 @@ def _dexp(c, e, p):
51895188
# rounding down
51905189
shift = e + q
51915190
if shift >= 0:
5192-
cshift = c * 10 ** shift
5191+
cshift = c * 10**shift
51935192
else:
5194-
cshift = c // 10 ** -shift
5193+
cshift = c // 10**-shift
51955194
quot, rem = divmod(cshift, _log10_digits(q))
51965195

51975196
# reduce remainder back to original precision
5198-
rem = _div_nearest(rem, 10 ** extra)
5197+
rem = _div_nearest(rem, 10**extra)
51995198

52005199
# error in result of _iexp < 120; error after division < 0.62
5201-
return _div_nearest(_iexp(rem, 10 ** p), 1000), quot - p + 3
5200+
return _div_nearest(_iexp(rem, 10**p), 1000), quot - p + 3
52025201

52035202

52045203
def _dpower(xc, xe, yc, ye, p):
@@ -5225,17 +5224,17 @@ def _dpower(xc, xe, yc, ye, p):
52255224
# compute product y*log(x) = yc*lxc*10**(-p-b-1+ye) = pc*10**(-p-1)
52265225
shift = ye - b
52275226
if shift >= 0:
5228-
pc = lxc * yc * 10 ** shift
5227+
pc = lxc * yc * 10**shift
52295228
else:
5230-
pc = _div_nearest(lxc * yc, 10 ** -shift)
5229+
pc = _div_nearest(lxc * yc, 10**-shift)
52315230

52325231
if pc == 0:
52335232
# we prefer a result that isn't exactly 1; this makes it
52345233
# easier to compute a correctly rounded result in __pow__
52355234
if (len(str(xc)) + xe >= 1) == (yc > 0): # if x**y > 1:
52365235
coeff, exp = 10 ** (p - 1) + 1, 1 - p
52375236
else:
5238-
coeff, exp = 10 ** p - 1, -p
5237+
coeff, exp = 10**p - 1, -p
52395238
else:
52405239
coeff, exp = _dexp(pc, -(p + 1), p + 1)
52415240
coeff = _div_nearest(coeff, 10)
@@ -5348,7 +5347,12 @@ def _convert_for_comparison(self, other, equality_op=False):
53485347
flags=[],
53495348
)
53505349

5351-
ExtendedContext = Context(prec=9, rounding=ROUND_HALF_EVEN, traps=[], flags=[],)
5350+
ExtendedContext = Context(
5351+
prec=9,
5352+
rounding=ROUND_HALF_EVEN,
5353+
traps=[],
5354+
flags=[],
5355+
)
53525356

53535357

53545358
##### crud for parsing strings #############################################

0 commit comments

Comments
 (0)