Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
5b5da3c
Add missing `__annotations__` variable into module
moreal Aug 9, 2021
eea1945
Refactor `Option<T>` handling
moreal Aug 10, 2021
ac0ae8b
Merge pull request #2823 from moreal/bugfix/missing-annotations
youknowone Aug 10, 2021
e01995d
socket: use libc::hstrerror
deantvv Aug 10, 2021
4812686
Merge pull request #2826 from deantvv/socket-hstrerror
youknowone Aug 10, 2021
a136db2
Add __alloc__ for bytearray, add note to tests.
DimitrisJim Aug 10, 2021
2c6208a
Add `math_perm` method
leesungbin Aug 10, 2021
a4fd014
Fixes `repr` of functions defined in classes
sobolevn Aug 10, 2021
04c9ae0
Fix bytearray.__init__.
DimitrisJim Aug 10, 2021
08614bf
Merge pull request #2830 from DimitrisJim/bytearray_init_alloc
youknowone Aug 10, 2021
7e2efb4
Fixes that `id()` of `tuple` was changing on `* 1`, refs #2840
sobolevn Aug 10, 2021
9f497fb
Add test_float from CPython 3.9.1
fanninpm Feb 14, 2021
fae7b0e
Implement __ceil__ for float type
fanninpm Feb 14, 2021
95b514b
Implement __floor__ for float type
fanninpm Feb 14, 2021
d451619
Enable __floor__, __ceil__ test snippet for float
Tetramad Aug 10, 2021
b4810f1
Merge pull request #2828 from Tetramad/float
youknowone Aug 11, 2021
2705fb2
Update vm/src/builtins/tuple.rs
sobolevn Aug 11, 2021
9ba674a
Merge pull request #2841 from sobolevn/issue-2840
youknowone Aug 11, 2021
571d9c4
add deque __iadd__ method
eldpswp99 Aug 11, 2021
56469ae
Merge pull request #2843 from eldpswp99/add_deque_iadd
youknowone Aug 11, 2021
49a30b9
Fixed unwrapping in frame.rs
Arnab1181412 Aug 11, 2021
3500a58
fix: make dict.{__or__,__ror__,__ior__} with other types should retur…
voidsatisfaction Aug 11, 2021
101fd80
Merge pull request #2846 from Arnab1181412/master
DimitrisJim Aug 11, 2021
20cb4ac
Fixed to use PathLike in imghdr.py
tony-jinwoo-ahn Aug 11, 2021
6bd69af
Merge pull request #2848 from voidsatisfaction/fix-dict-or-ror-ior-re…
youknowone Aug 11, 2021
cae4113
Merge pull request #2850 from tony-jinwoo-ahn/_PathLike
youknowone Aug 11, 2021
0906728
Adds `__rmul__` to `collections.deque` (#2844)
sobolevn Aug 11, 2021
03a9d60
Refactor Buffer Protocol (mostly namings) (#2849)
youknowone Aug 11, 2021
37f66dd
`id()` for `bytes` stays the same after `* 1`, refs #2840
sobolevn Aug 11, 2021
1a57ef0
tp_cmp -> tp_richcompare
youknowone Aug 11, 2021
94d046b
Merge pull request #2858 from sobolevn/bytes-mul-1
youknowone Aug 11, 2021
01c106b
Merge pull request #2857 from youknowone/richcompare
youknowone Aug 11, 2021
0c4d579
Fix length hint for dictionary iterators.
DimitrisJim Aug 11, 2021
5982e8c
Merge pull request #2859 from DimitrisJim/fix_faulty_length_hint
DimitrisJim Aug 11, 2021
4e60bcd
clean up #[pymethod(magic)]
youknowone Aug 11, 2021
08b758c
Merge pull request #2861 from youknowone/pymethod-magic
DimitrisJim Aug 11, 2021
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
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions Lib/imghdr.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Recognize image file formats based on their first few bytes."""

#from os import PathLike
from os import PathLike

__all__ = ["what"]

Expand All @@ -14,8 +14,7 @@ def what(file, h=None):
f = None
try:
if h is None:
# if isinstance(file, (str, PathLike))
if isinstance(file, str): # FIXME(corona10): RustPython doesn't support PathLike yet.
if isinstance(file, (str, PathLike)):
f = FileIO(file, 'rb')
h = f.read(32)
else:
Expand Down
2 changes: 0 additions & 2 deletions Lib/test/seq_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,6 @@ def __getitem__(self, key):
return str(key) + '!!!'
self.assertEqual(next(iter(T((1,2)))), 1)

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_repeat(self):
for m in range(4):
s = tuple(range(m))
Expand Down
22 changes: 13 additions & 9 deletions Lib/test/test_bytes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1449,8 +1449,11 @@ def test_irepeat_1char(self):
self.assertEqual(b, b1)
self.assertIs(b, b1)

# TODO: RUSTPYTHON
@unittest.expectedFailure
# NOTE: RUSTPYTHON:
#
# The second instance of self.assertGreater was replaced with
# self.assertGreaterEqual since, in RustPython, the underlying storage
# is a Vec which doesn't require trailing null byte.
def test_alloc(self):
b = bytearray()
alloc = b.__alloc__()
Expand All @@ -1459,12 +1462,15 @@ def test_alloc(self):
for i in range(100):
b += b"x"
alloc = b.__alloc__()
self.assertGreater(alloc, len(b)) # including trailing null byte
self.assertGreaterEqual(alloc, len(b)) # NOTE: RUSTPYTHON patched
if alloc not in seq:
seq.append(alloc)

# TODO: RUSTPYTHON
@unittest.expectedFailure
# NOTE: RUSTPYTHON:
#
# The usages of self.assertGreater were replaced with
# self.assertGreaterEqual since, in RustPython, the underlying storage
# is a Vec which doesn't require trailing null byte.
def test_init_alloc(self):
b = bytearray()
def g():
Expand All @@ -1475,12 +1481,12 @@ def g():
self.assertEqual(len(b), len(a))
self.assertLessEqual(len(b), i)
alloc = b.__alloc__()
self.assertGreater(alloc, len(b)) # including trailing null byte
self.assertGreaterEqual(alloc, len(b)) # NOTE: RUSTPYTHON patched
b.__init__(g())
self.assertEqual(list(b), list(range(1, 100)))
self.assertEqual(len(b), 99)
alloc = b.__alloc__()
self.assertGreater(alloc, len(b))
self.assertGreaterEqual(alloc, len(b)) # NOTE: RUSTPYTHON patched

def test_extend(self):
orig = b'hello'
Expand Down Expand Up @@ -1999,8 +2005,6 @@ class ByteArraySubclassTest(SubclassTest, unittest.TestCase):
basetype = bytearray
type2test = ByteArraySubclass

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_init_override(self):
class subclass(bytearray):
def __init__(me, newarg=1, *args, **kwargs):
Expand Down
11 changes: 2 additions & 9 deletions Lib/test/test_deque.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,6 @@ def test_add(self):
with self.assertRaises(TypeError):
deque('abc') + 'def'

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_iadd(self):
d = deque('a')
d += 'bcd'
Expand Down Expand Up @@ -357,8 +355,6 @@ def test_insert_bug_26194(self):
else:
self.assertEqual(d[i-1], 'Z')

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_imul(self):
for n in (-10, -1, 0, 1, 2, 10, 1000):
d = deque()
Expand Down Expand Up @@ -390,8 +386,6 @@ def test_imul(self):
self.assertEqual(d, deque(('abcdef' * n)[-500:]))
self.assertEqual(d.maxlen, 500)

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_mul(self):
d = deque('abc')
self.assertEqual(d * -5, deque())
Expand Down Expand Up @@ -1005,12 +999,11 @@ def test_subscript(self):
def test_free_after_iterating(self):
# For now, bypass tests that require slicing
self.skipTest("Exhausted deque iterator doesn't free a deque")

@unittest.skip("TODO: RUSTPYTHON TypeError: unexpected payload for __eq__")
def test_pickle(self):
pass

@unittest.skip("TODO: RUSTPYTHON TypeError: '+=' not supported between instances of 'deque' and 'deque'")

def test_iadd(self):
pass

Expand Down
28 changes: 28 additions & 0 deletions Lib/test/test_float.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,34 @@ def assertEqualAndEqualSign(self, a, b):
# distinguishes -0.0 and 0.0.
self.assertEqual((a, copysign(1.0, a)), (b, copysign(1.0, b)))

def test_float_floor(self):
self.assertIsInstance(float(0.5).__floor__(), int)
self.assertEqual(float(0.5).__floor__(), 0)
self.assertEqual(float(1.0).__floor__(), 1)
self.assertEqual(float(1.5).__floor__(), 1)
self.assertEqual(float(-0.5).__floor__(), -1)
self.assertEqual(float(-1.0).__floor__(), -1)
self.assertEqual(float(-1.5).__floor__(), -2)
self.assertEqual(float(1.23e167).__floor__(), 1.23e167)
self.assertEqual(float(-1.23e167).__floor__(), -1.23e167)
self.assertRaises(ValueError, float("nan").__floor__)
self.assertRaises(OverflowError, float("inf").__floor__)
self.assertRaises(OverflowError, float("-inf").__floor__)

def test_float_ceil(self):
self.assertIsInstance(float(0.5).__ceil__(), int)
self.assertEqual(float(0.5).__ceil__(), 1)
self.assertEqual(float(1.0).__ceil__(), 1)
self.assertEqual(float(1.5).__ceil__(), 2)
self.assertEqual(float(-0.5).__ceil__(), 0)
self.assertEqual(float(-1.0).__ceil__(), -1)
self.assertEqual(float(-1.5).__ceil__(), -1)
self.assertEqual(float(1.23e167).__ceil__(), 1.23e167)
self.assertEqual(float(-1.23e167).__ceil__(), -1.23e167)
self.assertRaises(ValueError, float("nan").__ceil__)
self.assertRaises(OverflowError, float("inf").__ceil__)
self.assertRaises(OverflowError, float("-inf").__ceil__)

# TODO: RUSTPYTHON
@unittest.expectedFailure
@support.requires_IEEE_754
Expand Down
6 changes: 0 additions & 6 deletions Lib/test/test_iterlen.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,6 @@ def setUp(self):
self.it = iter(d)
self.mutate = d.popitem

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_immutable_during_iteration(self):
super().test_immutable_during_iteration()

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

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_immutable_during_iteration(self):
super().test_immutable_during_iteration()

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

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_immutable_during_iteration(self):
super().test_immutable_during_iteration()

Expand Down
2 changes: 0 additions & 2 deletions Lib/test/test_math.py
Original file line number Diff line number Diff line change
Expand Up @@ -1814,8 +1814,6 @@ def _naive_prod(iterable, start=1):
self.assertEqual(type(prod([1, decimal.Decimal(2.0), 3, 4, 5, 6])),
decimal.Decimal)

# TODO: RUSTPYTHON
@unittest.expectedFailure
def testPerm(self):
perm = math.perm
factorial = math.factorial
Expand Down
3 changes: 2 additions & 1 deletion derive/src/pyclass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,8 @@ where
Self::#ident as _
}
};
if slot_name == "new" || slot_name == "buffer" {
const NON_ATOMIC_SLOTS: &[&str] = &["new", "as_buffer"];
if NON_ATOMIC_SLOTS.contains(&slot_name.as_str()) {
quote! {
slots.#slot_ident = Some(#into_func);
}
Expand Down
19 changes: 19 additions & 0 deletions extra_tests/snippets/builtin_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,3 +345,22 @@ def __new__(cls, *args, **kwargs):

assert type.__subclasshook__.__qualname__ == 'type.__subclasshook__'
assert object.__subclasshook__.__qualname__ == 'object.__subclasshook__'


# Regression to
# https://github.com/RustPython/RustPython/issues/2776

assert repr(BQ.one).startswith('<function BQ.one at 0x')
assert repr(BQ.one_st).startswith('<function BQ.one_st at 0x')

assert repr(BQ.two).startswith('<function AQ.two at 0x')
assert repr(BQ.two_st).startswith('<function AQ.two_st at 0x')

assert repr(BQ.three).startswith('<function BQ.three at 0x')
assert repr(BQ.three_st).startswith('<function BQ.three_st at 0x')


def my_repr_func():
pass

assert repr(my_repr_func).startswith('<function my_repr_func at 0x')
24 changes: 23 additions & 1 deletion extra_tests/snippets/bytes.py
Original file line number Diff line number Diff line change
Expand Up @@ -623,4 +623,26 @@ def __bytes__(self):

# Issue #2125
b = b'abc'
assert bytes(b) is b
assert bytes(b) is b


# Regression to
# https://github.com/RustPython/RustPython/issues/2840

a = b'123abc!?'
assert id(a) == id(a)
assert id(a) != id(a * -1)
assert id(a) != id(a * 0)
assert id(a) == id(a * 1) # only case when `id` stays the same
assert id(a) != id(a * 2)


class SubBytes(bytes):
pass

b = SubBytes(b'0123abc*&')
assert id(b) == id(b)
assert id(b) != id(b * -1)
assert id(b) != id(b * 0)
assert id(b) != id(b * 1)
assert id(b) != id(b * 2)
18 changes: 3 additions & 15 deletions extra_tests/snippets/dict_union.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,27 +42,15 @@ def test_dunion_ror0():
def test_dunion_other_types():
def perf_test_or(other_obj):
d={1:2}
try:
d.__or__(other_obj)
except:
return True
return False
return d.__or__(other_obj) is NotImplemented

def perf_test_ior(other_obj):
d={1:2}
try:
d.__ior__(other_obj)
except:
return True
return False
return d.__ior__(other_obj) is NotImplemented

def perf_test_ror(other_obj):
d={1:2}
try:
d.__ror__(other_obj)
except:
return True
return False
return d.__ror__(other_obj) is NotImplemented

test_fct={'__or__':perf_test_or, '__ror__':perf_test_ror, '__ior__':perf_test_ior}
others=['FooBar', 42, [36], set([19]), ['aa'], None]
Expand Down
14 changes: 11 additions & 3 deletions extra_tests/snippets/stdlib_math.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import math
from testutils import assert_raises
from testutils import assert_raises, skip_if_unsupported

NAN = float('nan')
INF = float('inf')
Expand All @@ -21,11 +21,19 @@
assert int.__ceil__

# assert float.__trunc__
with assert_raises(AttributeError):


def float_floor_exists():
assert float.__floor__
with assert_raises(AttributeError):


def float_ceil_exists():
assert float.__ceil__


skip_if_unsupported(3, 9, float_floor_exists)
skip_if_unsupported(3, 9, float_ceil_exists)

assert math.trunc(2) == 2
assert math.ceil(3) == 3
assert math.floor(4) == 4
Expand Down
11 changes: 11 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,17 @@ fn write_profile(matches: &ArgMatches) -> Result<(), Box<dyn std::error::Error>>
fn run_rustpython(vm: &VirtualMachine, matches: &ArgMatches) -> PyResult<()> {
let scope = vm.new_scope_with_builtins();
let main_module = vm.new_module("__main__", scope.globals.clone());
main_module
.dict()
.and_then(|d| {
d.set_item(
"__annotations__",
vm.ctx.new_dict().as_object().to_owned(),
vm,
)
.ok()
})
.expect("Failed to initialize __main__.__annotations__");

vm.get_attribute(vm.sys_module.clone(), "modules")?
.set_item("__main__", main_module, vm)?;
Expand Down
2 changes: 1 addition & 1 deletion vm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ indexmap = "1.0.2"
ahash = "0.7.2"
crc = "^1.0.0"
bitflags = "1.2.1"
libc = "0.2.95"
libc = "0.2.99"
nix = "0.20.0"
csv-core = "0.1"
paste = "1.0.5"
Expand Down
4 changes: 2 additions & 2 deletions vm/src/builtins/asyncgenerator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ impl PyAsyncGen {
zelf.inner.repr(zelf.get_id())
}

#[pymethod(name = "__aiter__")]
#[pymethod(magic)]
fn aiter(zelf: PyRef<Self>, _vm: &VirtualMachine) -> PyRef<Self> {
zelf
}

#[pymethod(name = "__anext__")]
#[pymethod(magic)]
fn anext(zelf: PyRef<Self>, vm: &VirtualMachine) -> PyAsyncGenASend {
Self::asend(zelf, vm.ctx.none(), vm)
}
Expand Down
Loading