Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions Lib/_markupbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ def updatepos(self, i, j):
if i >= j:
return j
rawdata = self.rawdata
nlines = rawdata.count("\n", i, j)
if nlines:
if (nlines := rawdata.count("\n", i, j)):
self.lineno = self.lineno + nlines
pos = rawdata.rindex("\n", i, j) # Should not fail
self.offset = j-(pos+1)
Expand Down Expand Up @@ -291,8 +290,7 @@ def _parse_doctype_attlist(self, i, declstartpos):
if not c:
return -1
if c in "'\"":
m = _declstringlit_match(rawdata, j)
if m:
if (m := _declstringlit_match(rawdata, j)):
j = m.end()
else:
return -1
Expand Down Expand Up @@ -359,8 +357,7 @@ def _parse_doctype_entity(self, i, declstartpos):
if not c:
return -1
if c in "'\"":
m = _declstringlit_match(rawdata, j)
if m:
if (m := _declstringlit_match(rawdata, j)):
j = m.end()
else:
return -1 # incomplete
Expand All @@ -378,8 +375,7 @@ def _scan_name(self, i, declstartpos):
n = len(rawdata)
if i == n:
return None, -1
m = _declname_match(rawdata, i)
if m:
if (m := _declname_match(rawdata, i)):
s = m.group()
name = s.strip()
if (i + len(s)) == n:
Expand Down
112 changes: 38 additions & 74 deletions Lib/_pydecimal.py
Original file line number Diff line number Diff line change
Expand Up @@ -886,35 +886,31 @@ def __lt__(self, other, context=None):
self, other = _convert_for_comparison(self, other)
if other is NotImplemented:
return other
ans = self._compare_check_nans(other, context)
if ans:
if self._compare_check_nans(other, context):
return False
return self._cmp(other) < 0

def __le__(self, other, context=None):
self, other = _convert_for_comparison(self, other)
if other is NotImplemented:
return other
ans = self._compare_check_nans(other, context)
if ans:
if self._compare_check_nans(other, context):
return False
return self._cmp(other) <= 0

def __gt__(self, other, context=None):
self, other = _convert_for_comparison(self, other)
if other is NotImplemented:
return other
ans = self._compare_check_nans(other, context)
if ans:
if self._compare_check_nans(other, context):
return False
return self._cmp(other) > 0

def __ge__(self, other, context=None):
self, other = _convert_for_comparison(self, other)
if other is NotImplemented:
return other
ans = self._compare_check_nans(other, context)
if ans:
if self._compare_check_nans(other, context):
return False
return self._cmp(other) >= 0

Expand All @@ -930,8 +926,7 @@ def compare(self, other, context=None):

# Compare(NaN, NaN) = NaN
if (self._is_special or other and other._is_special):
ans = self._check_nans(other, context)
if ans:
if (ans := self._check_nans(other, context)):
return ans

return Decimal(self._cmp(other))
Expand Down Expand Up @@ -1090,10 +1085,8 @@ def __neg__(self, context=None):

Rounds, if it has reason.
"""
if self._is_special:
ans = self._check_nans(context=context)
if ans:
return ans
if self._is_special and (ans := self._check_nans(context=context)):
return ans

if context is None:
context = getcontext()
Expand All @@ -1112,10 +1105,8 @@ def __pos__(self, context=None):

Rounds the number (if more than precision digits)
"""
if self._is_special:
ans = self._check_nans(context=context)
if ans:
return ans
if self._is_special and (ans := self._check_nans(context=context)):
return ans

if context is None:
context = getcontext()
Expand All @@ -1138,10 +1129,8 @@ def __abs__(self, round=True, context=None):
if not round:
return self.copy_abs()

if self._is_special:
ans = self._check_nans(context=context)
if ans:
return ans
if self._is_special and (ans := self._check_nans(context=context)):
return ans

if self._sign:
ans = self.__neg__(context=context)
Expand All @@ -1163,8 +1152,7 @@ def __add__(self, other, context=None):
context = getcontext()

if self._is_special or other._is_special:
ans = self._check_nans(other, context)
if ans:
if (ans := self._check_nans(other, context)):
return ans

if self._isinfinity():
Expand Down Expand Up @@ -1244,10 +1232,9 @@ def __sub__(self, other, context=None):
if other is NotImplemented:
return other

if self._is_special or other._is_special:
ans = self._check_nans(other, context=context)
if ans:
return ans
if (self._is_special or other._is_special
and (ans := self._check_nans(other, context=context))):
return ans

# self - other is computed as self + other.copy_negate()
return self.__add__(other.copy_negate(), context=context)
Expand Down Expand Up @@ -1275,8 +1262,7 @@ def __mul__(self, other, context=None):
resultsign = self._sign ^ other._sign

if self._is_special or other._is_special:
ans = self._check_nans(other, context)
if ans:
if (ans := self._check_nans(other, context)):
return ans

if self._isinfinity():
Expand Down Expand Up @@ -1329,8 +1315,7 @@ def __truediv__(self, other, context=None):
sign = self._sign ^ other._sign

if self._is_special or other._is_special:
ans = self._check_nans(other, context)
if ans:
if (ans := self._check_nans(other, context)):
return ans

if self._isinfinity() and other._isinfinity():
Expand Down Expand Up @@ -1427,8 +1412,7 @@ def __divmod__(self, other, context=None):
if context is None:
context = getcontext()

ans = self._check_nans(other, context)
if ans:
if (ans := self._check_nans(other, context)):
return (ans, ans)

sign = self._sign ^ other._sign
Expand Down Expand Up @@ -1470,8 +1454,7 @@ def __mod__(self, other, context=None):
if context is None:
context = getcontext()

ans = self._check_nans(other, context)
if ans:
if (ans := self._check_nans(other, context)):
return ans

if self._isinfinity():
Expand Down Expand Up @@ -1502,8 +1485,7 @@ def remainder_near(self, other, context=None):

other = _convert_other(other, raiseit=True)

ans = self._check_nans(other, context)
if ans:
if (ans := self._check_nans(other, context)):
return ans

# self == +/-infinity -> InvalidOperation
Expand Down Expand Up @@ -1577,8 +1559,7 @@ def __floordiv__(self, other, context=None):
if context is None:
context = getcontext()

ans = self._check_nans(other, context)
if ans:
if (ans := self._check_nans(other, context)):
return ans

if self._isinfinity():
Expand Down Expand Up @@ -2316,8 +2297,7 @@ def __pow__(self, other, modulo=None, context=None):
context = getcontext()

# either argument is a NaN => result is NaN
ans = self._check_nans(other, context)
if ans:
if (ans := self._check_nans(other, context)):
return ans

# 0**0 = NaN (!), x**0 = 1 for nonzero x (including +/-Infinity)
Expand Down Expand Up @@ -2511,8 +2491,7 @@ def normalize(self, context=None):
context = getcontext()

if self._is_special:
ans = self._check_nans(context=context)
if ans:
if (ans := self._check_nans(context=context)):
return ans

dup = self._fix(context)
Expand Down Expand Up @@ -2542,8 +2521,7 @@ def quantize(self, exp, rounding=None, context=None):
rounding = context.rounding

if self._is_special or exp._is_special:
ans = self._check_nans(exp, context)
if ans:
if (ans := self._check_nans(exp, context)):
return ans

if exp._isinfinity() or self._isinfinity():
Expand Down Expand Up @@ -2673,8 +2651,7 @@ def to_integral_exact(self, rounding=None, context=None):
this method except that it doesn't raise Inexact or Rounded.
"""
if self._is_special:
ans = self._check_nans(context=context)
if ans:
if (ans := self._check_nans(context=context)):
return ans
return Decimal(self)
if self._exp >= 0:
Expand All @@ -2698,8 +2675,7 @@ def to_integral_value(self, rounding=None, context=None):
if rounding is None:
rounding = context.rounding
if self._is_special:
ans = self._check_nans(context=context)
if ans:
if (ans := self._check_nans(context=context)):
return ans
return Decimal(self)
if self._exp >= 0:
Expand All @@ -2716,8 +2692,7 @@ def sqrt(self, context=None):
context = getcontext()

if self._is_special:
ans = self._check_nans(context=context)
if ans:
if (ans := self._check_nans(context=context)):
return ans

if self._isinfinity() and self._sign == 0:
Expand Down Expand Up @@ -2923,8 +2898,7 @@ def compare_signal(self, other, context=None):
NaNs taking precedence over quiet NaNs.
"""
other = _convert_other(other, raiseit = True)
ans = self._compare_check_nans(other, context)
if ans:
if (ans := self._compare_check_nans(other, context)):
return ans
return self.compare(other, context=context)

Expand Down Expand Up @@ -3036,8 +3010,7 @@ def exp(self, context=None):
context = getcontext()

# exp(NaN) = NaN
ans = self._check_nans(context=context)
if ans:
if (ans := self._check_nans(context=context)):
return ans

# exp(-Infinity) = 0
Expand Down Expand Up @@ -3192,8 +3165,7 @@ def ln(self, context=None):
context = getcontext()

# ln(NaN) = NaN
ans = self._check_nans(context=context)
if ans:
if (ans := self._check_nans(context=context)):
return ans

# ln(0.0) == -Infinity
Expand Down Expand Up @@ -3272,8 +3244,7 @@ def log10(self, context=None):
context = getcontext()

# log10(NaN) = NaN
ans = self._check_nans(context=context)
if ans:
if (ans := self._check_nans(context=context)):
return ans

# log10(0.0) == -Infinity
Expand Down Expand Up @@ -3325,8 +3296,7 @@ def logb(self, context=None):
without limiting the resulting exponent).
"""
# logb(NaN) = NaN
ans = self._check_nans(context=context)
if ans:
if (ans := self._check_nans(context=context)):
return ans

if context is None:
Expand Down Expand Up @@ -3496,8 +3466,7 @@ def next_minus(self, context=None):
if context is None:
context = getcontext()

ans = self._check_nans(context=context)
if ans:
if (ans := self._check_nans(context=context)):
return ans

if self._isinfinity() == -1:
Expand All @@ -3519,8 +3488,7 @@ def next_plus(self, context=None):
if context is None:
context = getcontext()

ans = self._check_nans(context=context)
if ans:
if (ans := self._check_nans(context=context)):
return ans

if self._isinfinity() == 1:
Expand Down Expand Up @@ -3551,8 +3519,7 @@ def next_toward(self, other, context=None):
if context is None:
context = getcontext()

ans = self._check_nans(other, context)
if ans:
if (ans := self._check_nans(other, context)):
return ans

comparison = self._cmp(other)
Expand Down Expand Up @@ -3636,8 +3603,7 @@ def rotate(self, other, context=None):

other = _convert_other(other, raiseit=True)

ans = self._check_nans(other, context)
if ans:
if (ans := self._check_nans(other, context)):
return ans

if other._exp != 0:
Expand Down Expand Up @@ -3669,8 +3635,7 @@ def scaleb(self, other, context=None):

other = _convert_other(other, raiseit=True)

ans = self._check_nans(other, context)
if ans:
if (ans := self._check_nans(other, context)):
return ans

if other._exp != 0:
Expand All @@ -3694,8 +3659,7 @@ def shift(self, other, context=None):

other = _convert_other(other, raiseit=True)

ans = self._check_nans(other, context)
if ans:
if (ans := self._check_nans(other, context)):
return ans

if other._exp != 0:
Expand Down
3 changes: 1 addition & 2 deletions Lib/_pyio.py
Original file line number Diff line number Diff line change
Expand Up @@ -1080,8 +1080,7 @@ def _peek_unlocked(self, n=0):
have = len(self._read_buf) - self._read_pos
if have < want or have <= 0:
to_read = self.buffer_size - have
current = self.raw.read(to_read)
if current:
if (current := self.raw.read(to_read)):
self._read_buf = self._read_buf[self._read_pos:] + current
self._read_pos = 0
return self._read_buf[self._read_pos:]
Expand Down
Loading