Merge pull request #1950 from TheAnyKey/TheAnyKey/p310_bitcount

Implement bitcount for int (Py310 BPO-29882)
This commit is contained in:
Jeong YunWon
2020-06-18 14:45:22 +09:00
committed by GitHub
9 changed files with 1495 additions and 81 deletions

2
Lib/re.py vendored
View File

@@ -158,7 +158,7 @@ class RegexFlag(enum.IntFlag):
TEMPLATE = sre_compile.SRE_FLAG_TEMPLATE # disable backtracking
T = TEMPLATE
DEBUG = sre_compile.SRE_FLAG_DEBUG # dump pattern after compilation
#TODO: globals().update(RegexFlag.__members__) once mappingproxy has __iter__
# TODO: globals().update(RegexFlag.__members__) once mappingproxy has __iter__
for name in ("ASCII","IGNORECASE","LOCALE","UNICODE","MULTILINE","DOTALL",
"VERBOSE","A","I","L","U","M","S","X","TEMPLATE","T","DEBUG"):
globals()[name] = getattr(RegexFlag, name)

View File

@@ -614,7 +614,7 @@ class Regrtest:
# If we're on windows and this is the parent runner (not a worker),
# track the load average.
# TODO: RustPython
# TODO: RUSTPYTHON
# if sys.platform == 'win32' and (self.ns.worker_args is None):
# from test.libregrtest.win_utils import WindowsLoadTracker

View File

@@ -308,9 +308,9 @@ class TestDecorators(unittest.TestCase):
return 'eggs'
self.assertEqual(Class.inner(), 'spam')
#self.assertEqual(Class.outer(), 'eggs') # TODO RustPython
#self.assertEqual(Class.outer(), 'eggs') # TODO: RUSTPYTHON
self.assertEqual(Class().inner(), 'spam')
#self.assertEqual(Class().outer(), 'eggs') # TODO RustPython
#self.assertEqual(Class().outer(), 'eggs') # TODO: RUSTPYTHON
class TestClassDecorators(unittest.TestCase):

1402
Lib/test/test_long.py Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -20,7 +20,7 @@ NAN = float('nan')
INF = float('inf')
NINF = float('-inf')
# TODO RustPython: float_info is so far not supported -> hard code for the moment
# TODO: RUSTPYTHON: float_info is so far not supported -> hard code for the moment
# FLOAT_MAX = sys.float_info.max
# FLOAT_MIN = sys.float_info.min
FLOAT_MAX = 1.7976931348623157e+308
@@ -249,7 +249,7 @@ class MathTests(unittest.TestCase):
self.ftest('e', math.e, 2.718281828459045235360287)
self.assertEqual(math.tau, 2*math.pi)
@unittest.skip('TODO: RustPython')
@unittest.skip('TODO: RUSTPYTHON')
def testAcos(self):
self.assertRaises(TypeError, math.acos)
self.ftest('acos(-1)', math.acos(-1), math.pi)
@@ -261,7 +261,7 @@ class MathTests(unittest.TestCase):
self.assertRaises(ValueError, math.acos, -1 - eps)
self.assertTrue(math.isnan(math.acos(NAN)))
@unittest.skip('TODO: RustPython')
@unittest.skip('TODO: RUSTPYTHON')
def testAcosh(self):
self.assertRaises(TypeError, math.acosh)
self.ftest('acosh(1)', math.acosh(1), 0)
@@ -272,7 +272,7 @@ class MathTests(unittest.TestCase):
self.assertRaises(ValueError, math.acosh, NINF)
self.assertTrue(math.isnan(math.acosh(NAN)))
@unittest.skip('TODO: RustPython')
@unittest.skip('TODO: RUSTPYTHON')
def testAsin(self):
self.assertRaises(TypeError, math.asin)
self.ftest('asin(-1)', math.asin(-1), -math.pi/2)
@@ -302,7 +302,7 @@ class MathTests(unittest.TestCase):
self.ftest('atan(-inf)', math.atan(NINF), -math.pi/2)
self.assertTrue(math.isnan(math.atan(NAN)))
@unittest.skip('TODO: RustPython')
@unittest.skip('TODO: RUSTPYTHON')
def testAtanh(self):
self.assertRaises(TypeError, math.atan)
self.ftest('atanh(0)', math.atanh(0), 0)
@@ -375,7 +375,7 @@ class MathTests(unittest.TestCase):
self.assertTrue(math.isnan(math.atan2(NAN, INF)))
self.assertTrue(math.isnan(math.atan2(NAN, NAN)))
@unittest.skip('TODO: RustPython')
@unittest.skip('TODO: RUSTPYTHON')
def testCeil(self):
self.assertRaises(TypeError, math.ceil)
self.assertEqual(int, type(math.ceil(0.5)))
@@ -409,7 +409,7 @@ class MathTests(unittest.TestCase):
self.assertRaises(TypeError, math.ceil, t)
self.assertRaises(TypeError, math.ceil, t, 0)
# TODO Rustpython
# TODO: RUSTPYTHON
# @requires_IEEE_754
def testCopysign(self):
self.assertEqual(math.copysign(1, 42), 1.0)
@@ -444,7 +444,7 @@ class MathTests(unittest.TestCase):
# similarly, copysign(2., NAN) could be 2. or -2.
self.assertEqual(abs(math.copysign(2., NAN)), 2.)
@unittest.skip('TODO: RustPython')
@unittest.skip('TODO: RUSTPYTHON')
def testCos(self):
self.assertRaises(TypeError, math.cos)
self.ftest('cos(-pi/2)', math.cos(-math.pi/2), 0, abs_tol=math.ulp(1))
@@ -476,7 +476,7 @@ class MathTests(unittest.TestCase):
self.ftest('degrees(-pi/4)', math.degrees(-math.pi/4), -45.0)
self.ftest('degrees(0)', math.degrees(0), 0)
@unittest.skip('TODO RustPython')
@unittest.skip('TODO: RUSTPYTHON')
def testExp(self):
self.assertRaises(TypeError, math.exp)
self.ftest('exp(-1)', math.exp(-1), 1/math.e)
@@ -503,7 +503,7 @@ class MathTests(unittest.TestCase):
self.assertRaises(ValueError, math.factorial, -1)
self.assertRaises(ValueError, math.factorial, -10**100)
@unittest.skip('TODO: RustPython')
@unittest.skip('TODO: RUSTPYTHON')
def testFactorialNonIntegers(self):
with self.assertWarns(DeprecationWarning):
self.assertEqual(math.factorial(5.0), 120)
@@ -526,7 +526,7 @@ class MathTests(unittest.TestCase):
with self.assertWarns(DeprecationWarning):
self.assertRaises(OverflowError, math.factorial, 1e100)
@unittest.skip('TODO RustPython')
@unittest.skip('TODO: RUSTPYTHON')
def testFloor(self):
self.assertRaises(TypeError, math.floor)
self.assertEqual(int, type(math.floor(0.5)))
@@ -599,7 +599,7 @@ class MathTests(unittest.TestCase):
self.assertTrue(math.isnan(math.frexp(NAN)[0]))
# TODO Rustpython
# TODO: RUSTPYTHON
# @requires_IEEE_754
# @unittest.skipIf(HAVE_DOUBLE_ROUNDING,
# "fsum is not exact on machines with double rounding")
@@ -738,9 +738,9 @@ class MathTests(unittest.TestCase):
self.assertRaises(TypeError, gcd, 120.0, 84)
self.assertRaises(TypeError, gcd, 120, 84.0)
self.assertRaises(TypeError, gcd, 120, 1, 84.0)
#self.assertEqual(gcd(MyIndexable(120), MyIndexable(84)), 12) # TODO RustPython
#self.assertEqual(gcd(MyIndexable(120), MyIndexable(84)), 12) # TODO: RUSTPYTHON
@unittest.skip('TODO: RustPython float support')
@unittest.skip('TODO: RUSTPYTHON float support')
def testHypot(self):
from decimal import Decimal
from fractions import Fraction
@@ -815,7 +815,7 @@ class MathTests(unittest.TestCase):
scale = FLOAT_MIN / 2.0 ** exp
self.assertEqual(math.hypot(4*scale, 3*scale), 5*scale)
@unittest.skip('TODO: RustPython')
@unittest.skip('TODO: RUSTPYTHON')
def testDist(self):
from decimal import Decimal as D
from fractions import Fraction as F
@@ -929,7 +929,7 @@ class MathTests(unittest.TestCase):
self.assertEqual(math.dist(p, q), 5*scale)
self.assertEqual(math.dist(q, p), 5*scale)
@unittest.skip('TODO RustPython')
@unittest.skip('TODO: RUSTPYTHON')
def testIsqrt(self):
# Test a variety of inputs, large and small.
test_values = (
@@ -1026,9 +1026,9 @@ class MathTests(unittest.TestCase):
self.assertRaises(TypeError, lcm, 120.0, 84)
self.assertRaises(TypeError, lcm, 120, 84.0)
self.assertRaises(TypeError, lcm, 120, 0, 84.0)
# self.assertEqual(lcm(MyIndexable(120), MyIndexable(84)), 840) # TODO RustPython
# self.assertEqual(lcm(MyIndexable(120), MyIndexable(84)), 840) # TODO: RUSTPYTHON
@unittest.skip('TODO RustPython')
@unittest.skip('TODO: RUSTPYTHON')
def testLdexp(self):
self.assertRaises(TypeError, math.ldexp)
self.ftest('ldexp(0,1)', math.ldexp(0,1), 0)
@@ -1061,7 +1061,7 @@ class MathTests(unittest.TestCase):
self.assertEqual(math.ldexp(NINF, n), NINF)
self.assertTrue(math.isnan(math.ldexp(NAN, n)))
@unittest.skip('TODO RustPython')
@unittest.skip('TODO: RUSTPYTHON')
def testLog(self):
self.assertRaises(TypeError, math.log)
self.ftest('log(1/e)', math.log(1/math.e), -1)
@@ -1078,7 +1078,7 @@ class MathTests(unittest.TestCase):
self.assertEqual(math.log(INF), INF)
self.assertTrue(math.isnan(math.log(NAN)))
@unittest.skip('TODO RustPython')
@unittest.skip('TODO: RUSTPYTHON')
def testLog1p(self):
self.assertRaises(TypeError, math.log1p)
for n in [2, 2**90, 2**300]:
@@ -1086,7 +1086,7 @@ class MathTests(unittest.TestCase):
self.assertRaises(ValueError, math.log1p, -1)
self.assertEqual(math.log1p(INF), INF)
# TODO Rustpython
# TODO: RUSTPYTHON
# @requires_IEEE_754
# def testLog2(self):
# self.assertRaises(TypeError, math.log2)
@@ -1105,7 +1105,7 @@ class MathTests(unittest.TestCase):
# self.assertRaises(ValueError, math.log2, NINF)
# self.assertTrue(math.isnan(math.log2(NAN)))
# TODO Rustpython
# TODO: RUSTPYTHON
# @requires_IEEE_754
# # log2() is not accurate enough on Mac OS X Tiger (10.4)
# @support.requires_mac_ver(10, 5)
@@ -1146,7 +1146,7 @@ class MathTests(unittest.TestCase):
self.assertTrue(math.isnan(modf_nan[0]))
self.assertTrue(math.isnan(modf_nan[1]))
@unittest.skip('TODO RustPython')
@unittest.skip('TODO: RUSTPYTHON')
def testPow(self):
self.assertRaises(TypeError, math.pow)
self.ftest('pow(0,1)', math.pow(0,1), 0)
@@ -1303,7 +1303,7 @@ class MathTests(unittest.TestCase):
self.ftest('radians(-45)', math.radians(-45), -math.pi/4)
self.ftest('radians(0)', math.radians(0), 0)
# TODO Rustpython
# TODO: RUSTPYTHON
# @requires_IEEE_754
# def testRemainder(self):
# from fractions import Fraction
@@ -1455,7 +1455,7 @@ class MathTests(unittest.TestCase):
self.assertEqual(math.sinh(NINF), NINF)
self.assertTrue(math.isnan(math.sinh(NAN)))
@unittest.skip('TODO RustPython')
@unittest.skip('TODO: RUSTPYTHON')
def testSqrt(self):
self.assertRaises(TypeError, math.sqrt)
self.ftest('sqrt(0)', math.sqrt(0), 0)
@@ -1479,7 +1479,7 @@ class MathTests(unittest.TestCase):
self.assertRaises(ValueError, math.tan, NINF)
self.assertTrue(math.isnan(math.tan(NAN)))
@unittest.skip('TODO RustPython')
@unittest.skip('TODO: RUSTPYTHON')
def testTanh(self):
self.assertRaises(TypeError, math.tanh)
self.ftest('tanh(0)', math.tanh(0), 0)
@@ -1489,7 +1489,7 @@ class MathTests(unittest.TestCase):
self.ftest('tanh(-inf)', math.tanh(NINF), -1)
self.assertTrue(math.isnan(math.tanh(NAN)))
# TODO Rustpython
# TODO: RUSTPYTHON
# @requires_IEEE_754
# def testTanhSign(self):
# # check that tanh(-0.) == -0. on IEEE 754 systems
@@ -1552,12 +1552,12 @@ class MathTests(unittest.TestCase):
self.assertFalse(math.isinf(0.))
self.assertFalse(math.isinf(1.))
# TODO Rustpython
# TODO: RUSTPYTHON
# @requires_IEEE_754
# def test_nan_constant(self):
# self.assertTrue(math.isnan(math.nan))
# TODO Rustpython
# TODO: RUSTPYTHON
# @requires_IEEE_754
# def test_inf_constant(self):
# self.assertTrue(math.isinf(math.inf))
@@ -1570,7 +1570,7 @@ class MathTests(unittest.TestCase):
# still fails this part of the test on some platforms. For now, we only
# *run* test_exceptions() in verbose mode, so that this isn't normally
# tested.
@unittest.skip('TODO RustPython')
@unittest.skip('TODO: RUSTPYTHON')
@unittest.skipUnless(verbose, 'requires verbose mode')
def test_exceptions(self):
try:
@@ -1603,7 +1603,7 @@ class MathTests(unittest.TestCase):
else:
self.fail("sqrt(-1) didn't raise ValueError")
# TODO Rustpython
# TODO: RUSTPYTHON
# @requires_IEEE_754
# def test_testfile(self):
# # Some tests need to be skipped on ancient OS X versions.
@@ -1661,7 +1661,7 @@ class MathTests(unittest.TestCase):
# self.fail('Failures in test_testfile:\n ' +
# '\n '.join(failures))
# TODO Rustpython
# TODO: RUSTPYTHON
# @requires_IEEE_754
# def test_mtestfile(self):
# fail_fmt = "{}: {}({!r}): {}"
@@ -1729,7 +1729,7 @@ class MathTests(unittest.TestCase):
# self.fail('Failures in test_mtestfile:\n ' +
# '\n '.join(failures))
@unittest.skip('TODO RustPython')
@unittest.skip('TODO: RUSTPYTHON')
def test_prod(self):
prod = math.prod
self.assertEqual(prod([]), 1)
@@ -1816,7 +1816,7 @@ class MathTests(unittest.TestCase):
self.assertEqual(type(prod([1, decimal.Decimal(2.0), 3, 4, 5, 6])),
decimal.Decimal)
@unittest.skip('TODO RustPython')
@unittest.skip('TODO: RUSTPYTHON')
def testPerm(self):
perm = math.perm
factorial = math.factorial
@@ -1881,7 +1881,7 @@ class MathTests(unittest.TestCase):
self.assertIs(type(perm(IntSubclass(5), IntSubclass(k))), int)
self.assertIs(type(perm(MyIndexable(5), MyIndexable(k))), int)
@unittest.skip('TODO RustPython')
@unittest.skip('TODO: RUSTPYTHON')
def testComb(self):
comb = math.comb
factorial = math.factorial
@@ -1952,7 +1952,7 @@ class MathTests(unittest.TestCase):
self.assertIs(type(comb(IntSubclass(5), IntSubclass(k))), int)
self.assertIs(type(comb(MyIndexable(5), MyIndexable(k))), int)
# TODO Rustpython
# TODO: RUSTPYTHON
# @requires_IEEE_754
# def test_nextafter(self):
# # around 2^52 and 2^63
@@ -2022,7 +2022,7 @@ class MathTests(unittest.TestCase):
# with self.subTest(x=x):
# self.assertEqual(math.ulp(-x), math.ulp(x))
@unittest.skip('TODO RustPython')
@unittest.skip('TODO: RUSTPYTHON')
def test_issue39871(self):
# A SystemError should not be raised if the first arg to atan2(),
# copysign(), or remainder() cannot be converted to a float.
@@ -2153,7 +2153,7 @@ class IsCloseTests(unittest.TestCase):
self.assertAllClose(integer_examples, rel_tol=1e-8)
self.assertAllNotClose(integer_examples, rel_tol=1e-9)
@unittest.skip('TODO RustPython')
@unittest.skip('TODO: RUSTPYTHON')
def test_decimals(self):
# test with Decimal values
from decimal import Decimal
@@ -2165,7 +2165,7 @@ class IsCloseTests(unittest.TestCase):
self.assertAllClose(decimal_examples, rel_tol=1e-8)
self.assertAllNotClose(decimal_examples, rel_tol=1e-9)
@unittest.skip('TODO Rustpython')
@unittest.skip('TODO: RUSTPYTHON')
def test_fractions(self):
# test with Fraction values
from fractions import Fraction

View File

@@ -10,63 +10,63 @@ class NamedExpressionInvalidTest(unittest.TestCase):
code = """x := 0"""
#with self.assertRaisesRegex(SyntaxError, "invalid syntax"):
with self.assertRaises(SyntaxError): # TODO RustPython
with self.assertRaises(SyntaxError): # TODO: RUSTPYTHON
exec(code, {}, {})
def test_named_expression_invalid_02(self):
code = """x = y := 0"""
#with self.assertRaisesRegex(SyntaxError, "invalid syntax"):
with self.assertRaises(SyntaxError): # TODO RustPython
with self.assertRaises(SyntaxError): # TODO: RUSTPYTHON
exec(code, {}, {})
def test_named_expression_invalid_03(self):
code = """y := f(x)"""
#with self.assertRaisesRegex(SyntaxError, "invalid syntax"):
with self.assertRaises(SyntaxError): # TODO RustPython
with self.assertRaises(SyntaxError): # TODO: RUSTPYTHON
exec(code, {}, {})
def test_named_expression_invalid_04(self):
code = """y0 = y1 := f(x)"""
#with self.assertRaisesRegex(SyntaxError, "invalid syntax"):
with self.assertRaises(SyntaxError): # TODO RustPython
with self.assertRaises(SyntaxError): # TODO: RUSTPYTHON
exec(code, {}, {})
def test_named_expression_invalid_06(self):
code = """((a, b) := (1, 2))"""
#with self.assertRaisesRegex(SyntaxError, "cannot use assignment expressions with tuple"):
with self.assertRaises(SyntaxError): # TODO RustPython
with self.assertRaises(SyntaxError): # TODO: RUSTPYTHON
exec(code, {}, {})
def test_named_expression_invalid_07(self):
code = """def spam(a = b := 42): pass"""
#with self.assertRaisesRegex(SyntaxError, "invalid syntax"):
with self.assertRaises(SyntaxError): # TODO RustPython
with self.assertRaises(SyntaxError): # TODO: RUSTPYTHON
exec(code, {}, {})
def test_named_expression_invalid_08(self):
code = """def spam(a: b := 42 = 5): pass"""
#with self.assertRaisesRegex(SyntaxError, "invalid syntax"):
with self.assertRaises(SyntaxError): # TODO RustPython
with self.assertRaises(SyntaxError): # TODO: RUSTPYTHON
exec(code, {}, {})
def test_named_expression_invalid_09(self):
code = """spam(a=b := 'c')"""
#with self.assertRaisesRegex(SyntaxError, "invalid syntax"):
with self.assertRaises(SyntaxError): # TODO RustPython
with self.assertRaises(SyntaxError): # TODO: RUSTPYTHON
exec(code, {}, {})
def test_named_expression_invalid_10(self):
code = """spam(x = y := f(x))"""
#with self.assertRaisesRegex(SyntaxError, "invalid syntax"):
with self.assertRaises(SyntaxError): # TODO RustPython
with self.assertRaises(SyntaxError): # TODO: RUSTPYTHON
exec(code, {}, {})
def test_named_expression_invalid_11(self):
@@ -74,7 +74,7 @@ class NamedExpressionInvalidTest(unittest.TestCase):
#with self.assertRaisesRegex(SyntaxError,
# "positional argument follows keyword argument"):
with self.assertRaises(SyntaxError): # TODO RustPython
with self.assertRaises(SyntaxError): # TODO: RUSTPYTHON
exec(code, {}, {})
def test_named_expression_invalid_12(self):
@@ -82,7 +82,7 @@ class NamedExpressionInvalidTest(unittest.TestCase):
#with self.assertRaisesRegex(SyntaxError,
# "positional argument follows keyword argument"):
with self.assertRaises(SyntaxError): # TODO RustPython
with self.assertRaises(SyntaxError): # TODO: RUSTPYTHON
exec(code, {}, {})
def test_named_expression_invalid_13(self):
@@ -90,14 +90,14 @@ class NamedExpressionInvalidTest(unittest.TestCase):
#with self.assertRaisesRegex(SyntaxError,
# "positional argument follows keyword argument"):
with self.assertRaises(SyntaxError): # TODO RustPython
with self.assertRaises(SyntaxError): # TODO: RUSTPYTHON
exec(code, {}, {})
def test_named_expression_invalid_14(self):
code = """(x := lambda: y := 1)"""
#with self.assertRaisesRegex(SyntaxError, "invalid syntax"):
with self.assertRaises(SyntaxError): # TODO RustPython
with self.assertRaises(SyntaxError): # TODO: RUSTPYTHON
exec(code, {}, {})
def test_named_expression_invalid_15(self):
@@ -105,24 +105,24 @@ class NamedExpressionInvalidTest(unittest.TestCase):
#with self.assertRaisesRegex(SyntaxError,
# "cannot use assignment expressions with lambda"):
with self.assertRaises(SyntaxError): # TODO RustPython
with self.assertRaises(SyntaxError): # TODO: RUSTPYTHON
exec(code, {}, {})
def test_named_expression_invalid_16(self):
code = "[i + 1 for i in i := [1,2]]"
#with self.assertRaisesRegex(SyntaxError, "invalid syntax"):
with self.assertRaises(SyntaxError): # TODO RustPython
with self.assertRaises(SyntaxError): # TODO: RUSTPYTHON
exec(code, {}, {})
def test_named_expression_invalid_17(self):
code = "[i := 0, j := 1 for i, j in [(1, 2), (3, 4)]]"
#with self.assertRaisesRegex(SyntaxError, "invalid syntax"):
with self.assertRaises(SyntaxError): # TODO RustPython
with self.assertRaises(SyntaxError): # TODO: RUSTPYTHON
exec(code, {}, {})
@unittest.expectedFailure # TODO RustPython
@unittest.expectedFailure # TODO: RUSTPYTHON
def test_named_expression_invalid_in_class_body(self):
code = """class Foo():
[(42, 1 + ((( j := i )))) for i in range(5)]
@@ -132,7 +132,7 @@ class NamedExpressionInvalidTest(unittest.TestCase):
"assignment expression within a comprehension cannot be used in a class body"):
exec(code, {}, {})
@unittest.expectedFailure # TODO RustPython
@unittest.expectedFailure # TODO: RUSTPYTHON
def test_named_expression_invalid_rebinding_comprehension_iteration_variable(self):
cases = [
("Local reuse", 'i', "[i := 0 for i in range(5)]"),
@@ -150,7 +150,7 @@ class NamedExpressionInvalidTest(unittest.TestCase):
with self.assertRaises(SyntaxError):
exec(code, {}, {})
@unittest.expectedFailure # TODO RustPython
@unittest.expectedFailure # TODO: RUSTPYTHON
def test_named_expression_invalid_rebinding_comprehension_inner_loop(self):
cases = [
("Inner reuse", 'j', "[i for i in range(5) if (j := 0) for j in range(5)]"),
@@ -166,7 +166,7 @@ class NamedExpressionInvalidTest(unittest.TestCase):
with self.assertRaisesRegex(SyntaxError, msg):
exec(f"lambda: {code}", {}) # Function scope
@unittest.expectedFailure # TODO RustPython
@unittest.expectedFailure # TODO: RUSTPYTHON
def test_named_expression_invalid_comprehension_iterable_expression(self):
cases = [
("Top level", "[i for i in (i := range(5))]"),
@@ -343,8 +343,8 @@ print(a)"""
self.assertEqual(res, [(1, 1, 1.0), (2, 2, 1.0), (3, 3, 1.0)])
self.assertEqual(y, 3)
# TODO RustPython,
@unittest.expectedFailure # TODO RustPython
# TODO: RUSTPYTHON,
@unittest.expectedFailure # TODO: RUSTPYTHON
def test_named_expression_scope_06(self):
res = [[spam := i for i in range(3)] for j in range(2)]
@@ -381,7 +381,7 @@ print(a)"""
self.assertEqual(res, [0, 2])
self.assertEqual(a, 2)
# TODO RustPython,
# TODO: RUSTPYTHON,
@unittest.expectedFailure
def test_named_expression_scope_10(self):
res = [b := [a := 1 for i in range(2)] for j in range(2)]
@@ -506,7 +506,7 @@ spam()"""
self.assertEqual(ns["x"], 2)
self.assertEqual(ns["result"], [0, 1, 2])
@unittest.expectedFailure # TODO RustPython
@unittest.expectedFailure # TODO: RUSTPYTHON
def test_named_expression_global_scope(self):
sentinel = object()
global GLOBAL_VAR

View File

@@ -136,7 +136,7 @@ class ScopeTests(unittest.TestCase):
h = g(2, 4, 6)
self.assertEqual(h(), 39)
@unittest.expectedFailure # TODO RustPython
@unittest.expectedFailure # TODO: RUSTPYTHON
def testFreeVarInMethod(self):
def test():
@@ -202,7 +202,7 @@ class ScopeTests(unittest.TestCase):
self.assertEqual(f(6), 720)
@unittest.expectedFailure # TODO RustPython
@unittest.expectedFailure # TODO: RUSTPYTHON
def testUnoptimizedNamespaces(self):
check_syntax_error(self, """if 1:
@@ -262,7 +262,7 @@ class ScopeTests(unittest.TestCase):
h = g(2, 4, 6)
self.assertEqual(h(), 18)
@unittest.expectedFailure # TODO RustPython
@unittest.expectedFailure # TODO: RUSTPYTHON
def testUnboundLocal(self):
def errorInOuter():
@@ -280,7 +280,7 @@ class ScopeTests(unittest.TestCase):
self.assertRaises(UnboundLocalError, errorInOuter)
self.assertRaises(NameError, errorInInner)
@unittest.expectedFailure # TODO RustPython
@unittest.expectedFailure # TODO: RUSTPYTHON
def testUnboundLocal_AfterDel(self):
# #4617: It is now legal to delete a cell variable.
# The following functions must obviously compile,
@@ -302,7 +302,7 @@ class ScopeTests(unittest.TestCase):
self.assertRaises(UnboundLocalError, errorInOuter)
self.assertRaises(NameError, errorInInner)
@unittest.expectedFailure # TODO RustPython
@unittest.expectedFailure # TODO: RUSTPYTHON
def testUnboundLocal_AugAssign(self):
# test for bug #1501934: incorrect LOAD/STORE_GLOBAL generation
exec("""if 1:
@@ -335,7 +335,7 @@ class ScopeTests(unittest.TestCase):
self.assertEqual(makeReturner2(a=11)()['a'], 11)
@unittest.expectedFailure # TODO RustPython
@unittest.expectedFailure # TODO: RUSTPYTHON
def testScopeOfGlobalStmt(self):
# Examples posted by Samuele Pedroni to python-dev on 3/1/2001
@@ -414,7 +414,7 @@ class ScopeTests(unittest.TestCase):
self.assertEqual(g.get(), 13)
""")
@unittest.expectedFailure # TODO RustPython
@unittest.expectedFailure # TODO: RUSTPYTHON
def testLeaks(self):
class Foo:
@@ -437,7 +437,7 @@ class ScopeTests(unittest.TestCase):
self.assertEqual(Foo.count, 0)
@unittest.expectedFailure # TODO RustPython
@unittest.expectedFailure # TODO: RUSTPYTHON
def testClassAndGlobal(self):
exec("""if 1:
@@ -460,7 +460,7 @@ class ScopeTests(unittest.TestCase):
self.assertTrue(X.passed)
""")
@unittest.expectedFailure # TODO RustPython
@unittest.expectedFailure # TODO: RUSTPYTHON
def testLocalsFunction(self):
def f(x):
@@ -568,7 +568,7 @@ class ScopeTests(unittest.TestCase):
self.assertRaises(TypeError, sys.settrace)
@unittest.expectedFailure # TODO RustPython
@unittest.expectedFailure # TODO: RUSTPYTHON
def testEvalExecFreeVars(self):
def f(x):
@@ -603,7 +603,7 @@ class ScopeTests(unittest.TestCase):
except NameError:
pass
@unittest.expectedFailure # TODO RustPython
@unittest.expectedFailure # TODO: RUSTPYTHON
def testEvalFreeVars(self):
def f(x):
@@ -661,7 +661,7 @@ class ScopeTests(unittest.TestCase):
self.assertEqual(c.dec(), 1)
self.assertEqual(c.dec(), 0)
@unittest.expectedFailure # TODO RustPython
@unittest.expectedFailure # TODO: RUSTPYTHON
def testGlobalInParallelNestedFunctions(self):
# A symbol table bug leaked the global statement from one
# function to other nested functions in the same block.
@@ -741,7 +741,7 @@ class ScopeTests(unittest.TestCase):
def b():
global a
@unittest.expectedFailure # TODO RustPython
@unittest.expectedFailure # TODO: RUSTPYTHON
def testClassNamespaceOverridesClosure(self):
# See #17853.
x = 42

View File

@@ -122,7 +122,7 @@ self.assertEqual(f'{x=!s}', 'x=' + str(x))
x = 2.71828
self.assertEqual(f'{x=:.2f}', 'x=' + format(x, '.2f'))
self.assertEqual(f'{x=:}', 'x=' + format(x, ''))
self.assertEqual(f'{x=!r:^20}', 'x=' + format(repr(x), '^20')) #TODO formatspecifier after conversion flsg is currently not supported (also for classical fstrings)
self.assertEqual(f'{x=!r:^20}', 'x=' + format(repr(x), '^20')) # TODO formatspecifier after conversion flsg is currently not supported (also for classical fstrings)
self.assertEqual(f'{x=!s:^20}', 'x=' + format(str(x), '^20'))
self.assertEqual(f'{x=!a:^20}', 'x=' + format(ascii(x), '^20'))

View File

@@ -653,6 +653,18 @@ impl PyInt {
fn denominator(&self) -> usize {
1
}
#[pymethod]
/// Returns the number of ones 1 an int. When the number is < 0,
/// then it returns the number of ones of the absolute value.
fn bit_count(&self) -> u32 {
self.value
.to_u32_digits()
.1
.iter()
.map(|n| n.count_ones())
.sum()
}
}
#[derive(FromArgs)]