Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Fixed new_attribute_error and added more tests for property
  • Loading branch information
skinnyBat committed Mar 9, 2019
commit 3c3c1f2b6f6fd8e1938b63153554f90cfa611ac9
16 changes: 0 additions & 16 deletions tests/snippets/class.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,6 @@ def square(self):
assert foo.square() == 25


class Fubar:
def __init__(self):
self.x = 100

@property
def foo(self):
value = self.x
self.x += 1
return value


f = Fubar()
assert f.foo == 100
assert f.foo == 101


class Bar:
""" W00t """
def __init__(self, x):
Expand Down
32 changes: 32 additions & 0 deletions tests/snippets/property.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from testutils import assertRaises


class Fubar:
def __init__(self):
self.x = 100

@property
def foo(self):
value = self.x
self.x += 1
return value


f = Fubar()
assert f.foo == 100
assert f.foo == 101


null_property = property()
assert type(null_property) is property

p = property(lambda x: x[0])
assert p.__get__((2,), tuple) == 2
# TODO owner parameter is optional
# assert p.__get__((2,)) == 2

with assertRaises(AttributeError):
null_property.__get__((), tuple)

with assertRaises(TypeError):
property.__new__(object)
2 changes: 1 addition & 1 deletion vm/src/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ impl VirtualMachine {
}

pub fn new_attribute_error(&mut self, msg: String) -> PyObjectRef {
let type_error = self.ctx.exceptions.arithmetic_error.clone();
let type_error = self.ctx.exceptions.attribute_error.clone();
self.new_exception(type_error, msg)
}

Expand Down