Skip to content

Commit aed3584

Browse files
authored
Merge pull request #65 from RustPython/master
Sync Fork from Upstream Repo
2 parents 668953c + 08b758c commit aed3584

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+658
-474
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Lib/imghdr.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Recognize image file formats based on their first few bytes."""
22

3-
#from os import PathLike
3+
from os import PathLike
44

55
__all__ = ["what"]
66

@@ -14,8 +14,7 @@ def what(file, h=None):
1414
f = None
1515
try:
1616
if h is None:
17-
# if isinstance(file, (str, PathLike))
18-
if isinstance(file, str): # FIXME(corona10): RustPython doesn't support PathLike yet.
17+
if isinstance(file, (str, PathLike)):
1918
f = FileIO(file, 'rb')
2019
h = f.read(32)
2120
else:

Lib/test/seq_tests.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,6 @@ def __getitem__(self, key):
311311
return str(key) + '!!!'
312312
self.assertEqual(next(iter(T((1,2)))), 1)
313313

314-
# TODO: RUSTPYTHON
315-
@unittest.expectedFailure
316314
def test_repeat(self):
317315
for m in range(4):
318316
s = tuple(range(m))

Lib/test/test_bytes.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1449,8 +1449,11 @@ def test_irepeat_1char(self):
14491449
self.assertEqual(b, b1)
14501450
self.assertIs(b, b1)
14511451

1452-
# TODO: RUSTPYTHON
1453-
@unittest.expectedFailure
1452+
# NOTE: RUSTPYTHON:
1453+
#
1454+
# The second instance of self.assertGreater was replaced with
1455+
# self.assertGreaterEqual since, in RustPython, the underlying storage
1456+
# is a Vec which doesn't require trailing null byte.
14541457
def test_alloc(self):
14551458
b = bytearray()
14561459
alloc = b.__alloc__()
@@ -1459,12 +1462,15 @@ def test_alloc(self):
14591462
for i in range(100):
14601463
b += b"x"
14611464
alloc = b.__alloc__()
1462-
self.assertGreater(alloc, len(b)) # including trailing null byte
1465+
self.assertGreaterEqual(alloc, len(b)) # NOTE: RUSTPYTHON patched
14631466
if alloc not in seq:
14641467
seq.append(alloc)
14651468

1466-
# TODO: RUSTPYTHON
1467-
@unittest.expectedFailure
1469+
# NOTE: RUSTPYTHON:
1470+
#
1471+
# The usages of self.assertGreater were replaced with
1472+
# self.assertGreaterEqual since, in RustPython, the underlying storage
1473+
# is a Vec which doesn't require trailing null byte.
14681474
def test_init_alloc(self):
14691475
b = bytearray()
14701476
def g():
@@ -1475,12 +1481,12 @@ def g():
14751481
self.assertEqual(len(b), len(a))
14761482
self.assertLessEqual(len(b), i)
14771483
alloc = b.__alloc__()
1478-
self.assertGreater(alloc, len(b)) # including trailing null byte
1484+
self.assertGreaterEqual(alloc, len(b)) # NOTE: RUSTPYTHON patched
14791485
b.__init__(g())
14801486
self.assertEqual(list(b), list(range(1, 100)))
14811487
self.assertEqual(len(b), 99)
14821488
alloc = b.__alloc__()
1483-
self.assertGreater(alloc, len(b))
1489+
self.assertGreaterEqual(alloc, len(b)) # NOTE: RUSTPYTHON patched
14841490

14851491
def test_extend(self):
14861492
orig = b'hello'
@@ -1999,8 +2005,6 @@ class ByteArraySubclassTest(SubclassTest, unittest.TestCase):
19992005
basetype = bytearray
20002006
type2test = ByteArraySubclass
20012007

2002-
# TODO: RUSTPYTHON
2003-
@unittest.expectedFailure
20042008
def test_init_override(self):
20052009
class subclass(bytearray):
20062010
def __init__(me, newarg=1, *args, **kwargs):

Lib/test/test_deque.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,6 @@ def test_add(self):
236236
with self.assertRaises(TypeError):
237237
deque('abc') + 'def'
238238

239-
# TODO: RUSTPYTHON
240-
@unittest.expectedFailure
241239
def test_iadd(self):
242240
d = deque('a')
243241
d += 'bcd'
@@ -357,8 +355,6 @@ def test_insert_bug_26194(self):
357355
else:
358356
self.assertEqual(d[i-1], 'Z')
359357

360-
# TODO: RUSTPYTHON
361-
@unittest.expectedFailure
362358
def test_imul(self):
363359
for n in (-10, -1, 0, 1, 2, 10, 1000):
364360
d = deque()
@@ -390,8 +386,6 @@ def test_imul(self):
390386
self.assertEqual(d, deque(('abcdef' * n)[-500:]))
391387
self.assertEqual(d.maxlen, 500)
392388

393-
# TODO: RUSTPYTHON
394-
@unittest.expectedFailure
395389
def test_mul(self):
396390
d = deque('abc')
397391
self.assertEqual(d * -5, deque())
@@ -1005,12 +999,11 @@ def test_subscript(self):
1005999
def test_free_after_iterating(self):
10061000
# For now, bypass tests that require slicing
10071001
self.skipTest("Exhausted deque iterator doesn't free a deque")
1008-
1002+
10091003
@unittest.skip("TODO: RUSTPYTHON TypeError: unexpected payload for __eq__")
10101004
def test_pickle(self):
10111005
pass
1012-
1013-
@unittest.skip("TODO: RUSTPYTHON TypeError: '+=' not supported between instances of 'deque' and 'deque'")
1006+
10141007
def test_iadd(self):
10151008
pass
10161009

Lib/test/test_float.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,34 @@ def assertEqualAndEqualSign(self, a, b):
324324
# distinguishes -0.0 and 0.0.
325325
self.assertEqual((a, copysign(1.0, a)), (b, copysign(1.0, b)))
326326

327+
def test_float_floor(self):
328+
self.assertIsInstance(float(0.5).__floor__(), int)
329+
self.assertEqual(float(0.5).__floor__(), 0)
330+
self.assertEqual(float(1.0).__floor__(), 1)
331+
self.assertEqual(float(1.5).__floor__(), 1)
332+
self.assertEqual(float(-0.5).__floor__(), -1)
333+
self.assertEqual(float(-1.0).__floor__(), -1)
334+
self.assertEqual(float(-1.5).__floor__(), -2)
335+
self.assertEqual(float(1.23e167).__floor__(), 1.23e167)
336+
self.assertEqual(float(-1.23e167).__floor__(), -1.23e167)
337+
self.assertRaises(ValueError, float("nan").__floor__)
338+
self.assertRaises(OverflowError, float("inf").__floor__)
339+
self.assertRaises(OverflowError, float("-inf").__floor__)
340+
341+
def test_float_ceil(self):
342+
self.assertIsInstance(float(0.5).__ceil__(), int)
343+
self.assertEqual(float(0.5).__ceil__(), 1)
344+
self.assertEqual(float(1.0).__ceil__(), 1)
345+
self.assertEqual(float(1.5).__ceil__(), 2)
346+
self.assertEqual(float(-0.5).__ceil__(), 0)
347+
self.assertEqual(float(-1.0).__ceil__(), -1)
348+
self.assertEqual(float(-1.5).__ceil__(), -1)
349+
self.assertEqual(float(1.23e167).__ceil__(), 1.23e167)
350+
self.assertEqual(float(-1.23e167).__ceil__(), -1.23e167)
351+
self.assertRaises(ValueError, float("nan").__ceil__)
352+
self.assertRaises(OverflowError, float("inf").__ceil__)
353+
self.assertRaises(OverflowError, float("-inf").__ceil__)
354+
327355
# TODO: RUSTPYTHON
328356
@unittest.expectedFailure
329357
@support.requires_IEEE_754

Lib/test/test_iterlen.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,6 @@ def setUp(self):
148148
self.it = iter(d)
149149
self.mutate = d.popitem
150150

151-
# TODO: RUSTPYTHON
152-
@unittest.expectedFailure
153151
def test_immutable_during_iteration(self):
154152
super().test_immutable_during_iteration()
155153

@@ -160,8 +158,6 @@ def setUp(self):
160158
self.it = iter(d.items())
161159
self.mutate = d.popitem
162160

163-
# TODO: RUSTPYTHON
164-
@unittest.expectedFailure
165161
def test_immutable_during_iteration(self):
166162
super().test_immutable_during_iteration()
167163

@@ -172,8 +168,6 @@ def setUp(self):
172168
self.it = iter(d.values())
173169
self.mutate = d.popitem
174170

175-
# TODO: RUSTPYTHON
176-
@unittest.expectedFailure
177171
def test_immutable_during_iteration(self):
178172
super().test_immutable_during_iteration()
179173

Lib/test/test_math.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1814,8 +1814,6 @@ def _naive_prod(iterable, start=1):
18141814
self.assertEqual(type(prod([1, decimal.Decimal(2.0), 3, 4, 5, 6])),
18151815
decimal.Decimal)
18161816

1817-
# TODO: RUSTPYTHON
1818-
@unittest.expectedFailure
18191817
def testPerm(self):
18201818
perm = math.perm
18211819
factorial = math.factorial

derive/src/pyclass.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,8 @@ where
395395
Self::#ident as _
396396
}
397397
};
398-
if slot_name == "new" || slot_name == "buffer" {
398+
const NON_ATOMIC_SLOTS: &[&str] = &["new", "as_buffer"];
399+
if NON_ATOMIC_SLOTS.contains(&slot_name.as_str()) {
399400
quote! {
400401
slots.#slot_ident = Some(#into_func);
401402
}

extra_tests/snippets/builtin_type.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,3 +345,22 @@ def __new__(cls, *args, **kwargs):
345345

346346
assert type.__subclasshook__.__qualname__ == 'type.__subclasshook__'
347347
assert object.__subclasshook__.__qualname__ == 'object.__subclasshook__'
348+
349+
350+
# Regression to
351+
# https://github.com/RustPython/RustPython/issues/2776
352+
353+
assert repr(BQ.one).startswith('<function BQ.one at 0x')
354+
assert repr(BQ.one_st).startswith('<function BQ.one_st at 0x')
355+
356+
assert repr(BQ.two).startswith('<function AQ.two at 0x')
357+
assert repr(BQ.two_st).startswith('<function AQ.two_st at 0x')
358+
359+
assert repr(BQ.three).startswith('<function BQ.three at 0x')
360+
assert repr(BQ.three_st).startswith('<function BQ.three_st at 0x')
361+
362+
363+
def my_repr_func():
364+
pass
365+
366+
assert repr(my_repr_func).startswith('<function my_repr_func at 0x')

0 commit comments

Comments
 (0)