Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 446285f

Browse filesBrowse files
authored
Merge pull request #4892 from Masorubka1/test_property.py
Update test_property.py from Cpython v3.11.2
2 parents a354f7b + c3d9a51 commit 446285f
Copy full SHA for 446285f

File tree

2 files changed

+31
-22
lines changed
Filter options

2 files changed

+31
-22
lines changed

‎Lib/test/test_property.py

Copy file name to clipboardExpand all lines: Lib/test/test_property.py
+28-19Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,23 @@ def test_property_set_name_incorrect_args(self):
226226
):
227227
p.__set_name__(*([0] * i))
228228

229+
def test_property_setname_on_property_subclass(self):
230+
# https://github.com/python/cpython/issues/100942
231+
# Copy was setting the name field without first
232+
# verifying that the copy was an actual property
233+
# instance. As a result, the code below was
234+
# causing a segfault.
235+
236+
class pro(property):
237+
def __new__(typ, *args, **kwargs):
238+
return "abcdef"
239+
240+
class A:
241+
pass
242+
243+
p = property.__new__(pro)
244+
p.__set_name__(A, 1)
245+
np = p.getter(lambda self: 1)
229246

230247
# Issue 5890: subclasses of property do not preserve method __doc__ strings
231248
class PropertySub(property):
@@ -341,43 +358,35 @@ def _format_exc_msg(self, msg):
341358
def setUpClass(cls):
342359
cls.obj = cls.cls()
343360

361+
# TODO: RUSTPYTHON
362+
@unittest.expectedFailure
344363
def test_get_property(self):
345-
with self.assertRaisesRegex(AttributeError, self._format_exc_msg("unreadable attribute")):
364+
with self.assertRaisesRegex(AttributeError, self._format_exc_msg("has no getter")):
346365
self.obj.foo
347366

367+
# TODO: RUSTPYTHON
368+
@unittest.expectedFailure
348369
def test_set_property(self):
349-
with self.assertRaisesRegex(AttributeError, self._format_exc_msg("can't set attribute")):
370+
with self.assertRaisesRegex(AttributeError, self._format_exc_msg("has no setter")):
350371
self.obj.foo = None
351372

373+
# TODO: RUSTPYTHON
374+
@unittest.expectedFailure
352375
def test_del_property(self):
353-
with self.assertRaisesRegex(AttributeError, self._format_exc_msg("can't delete attribute")):
376+
with self.assertRaisesRegex(AttributeError, self._format_exc_msg("has no deleter")):
354377
del self.obj.foo
355378

356379

357380
class PropertyUnreachableAttributeWithName(_PropertyUnreachableAttribute, unittest.TestCase):
358-
msg_format = "^{} 'foo'$"
381+
msg_format = r"^property 'foo' of 'PropertyUnreachableAttributeWithName\.cls' object {}$"
359382

360383
class cls:
361384
foo = property()
362385

363-
# TODO: RUSTPYTHON
364-
@unittest.expectedFailure
365-
def test_get_property(self): # TODO: RUSTPYTHON; remove this function when the test is fixed
366-
super().test_get_property()
367-
368-
# TODO: RUSTPYTHON
369-
@unittest.expectedFailure
370-
def test_set_property(self): # TODO: RUSTPYTHON; remove this function when the test is fixed
371-
super().test_get_property()
372-
373-
# TODO: RUSTPYTHON
374-
@unittest.expectedFailure
375-
def test_del_property(self): # TODO: RUSTPYTHON; remove this function when the test is fixed
376-
super().test_get_property()
377386

378387

379388
class PropertyUnreachableAttributeNoName(_PropertyUnreachableAttribute, unittest.TestCase):
380-
msg_format = "^{}$"
389+
msg_format = r"^property of 'PropertyUnreachableAttributeNoName\.cls' object {}$"
381390

382391
class cls:
383392
pass

‎vm/src/builtins/property.rs

Copy file name to clipboardExpand all lines: vm/src/builtins/property.rs
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ impl GetDescriptor for PyProperty {
5151
} else if let Some(getter) = zelf.getter.read().as_ref() {
5252
getter.call((obj,), vm)
5353
} else {
54-
Err(vm.new_attribute_error("unreadable attribute".to_string()))
54+
Err(vm.new_attribute_error("property has no getter".to_string()))
5555
}
5656
}
5757
}
@@ -73,14 +73,14 @@ impl PyProperty {
7373
if let Some(setter) = zelf.setter.read().as_ref() {
7474
setter.call((obj, value), vm).map(drop)
7575
} else {
76-
Err(vm.new_attribute_error("can't set attribute".to_owned()))
76+
Err(vm.new_attribute_error("property has no setter".to_owned()))
7777
}
7878
}
7979
PySetterValue::Delete => {
8080
if let Some(deleter) = zelf.deleter.read().as_ref() {
8181
deleter.call((obj,), vm).map(drop)
8282
} else {
83-
Err(vm.new_attribute_error("can't delete attribute".to_owned()))
83+
Err(vm.new_attribute_error("property has no deleter".to_owned()))
8484
}
8585
}
8686
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.