Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion Include/internal/pycore_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ extern "C" {
_PyObject_EXTRA_INIT \
.ob_refcnt = _Py_IMMORTAL_REFCNT, \
.ob_type = (type), \
.ob_region = (Py_region_ptr_with_tags_t){_Py_LOCAL_REGION} \
.ob_region = (Py_region_ptr_with_tags_t){_Py_IMMUTABLE} \
},
#define _PyVarObject_HEAD_INIT(type, size) \
{ \
Expand Down
2 changes: 1 addition & 1 deletion Include/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ static inline Py_region_ptr_with_tags_t Py_region_ptr_with_tags(Py_region_ptr_t
_PyObject_EXTRA_INIT \
{ _Py_IMMORTAL_REFCNT }, \
(type), \
(Py_region_ptr_with_tags_t){_Py_LOCAL_REGION} \
(Py_region_ptr_with_tags_t){_Py_IMMUTABLE} \
},
#else
#define PyObject_HEAD_INIT(type) \
Expand Down
10 changes: 5 additions & 5 deletions Lib/test/test_capi/test_abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def test_object_setattr(self):
self.assertRaises(RuntimeError, xsetattr, obj, 'evil', NULL)

self.assertRaises(RuntimeError, xsetattr, obj, 'evil', 'good')
self.assertRaises(AttributeError, xsetattr, 42, 'a', 5)
self.assertRaises(NotWriteableError, xsetattr, 42, 'a', 5)
self.assertRaises(TypeError, xsetattr, obj, 1, 5)
# CRASHES xsetattr(obj, NULL, 5)
# CRASHES xsetattr(NULL, 'a', 5)
Expand All @@ -136,7 +136,7 @@ def test_object_setattrstring(self):
self.assertRaises(RuntimeError, setattrstring, obj, b'evil', NULL)

self.assertRaises(RuntimeError, setattrstring, obj, b'evil', 'good')
self.assertRaises(AttributeError, setattrstring, 42, b'a', 5)
self.assertRaises(NotWriteableError, setattrstring, 42, b'a', 5)
self.assertRaises(TypeError, setattrstring, obj, 1, 5)
self.assertRaises(UnicodeDecodeError, setattrstring, obj, b'\xff', 5)
# CRASHES setattrstring(obj, NULL, 5)
Expand All @@ -153,7 +153,7 @@ def test_object_delattr(self):
xdelattr(obj, '\U0001f40d')
self.assertFalse(hasattr(obj, '\U0001f40d'))

self.assertRaises(AttributeError, xdelattr, 42, 'numerator')
self.assertRaises(NotWriteableError, xdelattr, 42, 'numerator')
self.assertRaises(RuntimeError, xdelattr, obj, 'evil')
self.assertRaises(TypeError, xdelattr, obj, 1)
# CRASHES xdelattr(obj, NULL)
Expand All @@ -170,7 +170,7 @@ def test_object_delattrstring(self):
delattrstring(obj, '\U0001f40d'.encode())
self.assertFalse(hasattr(obj, '\U0001f40d'))

self.assertRaises(AttributeError, delattrstring, 42, b'numerator')
self.assertRaises(NotWriteableError, delattrstring, 42, b'numerator')
self.assertRaises(RuntimeError, delattrstring, obj, b'evil')
self.assertRaises(UnicodeDecodeError, delattrstring, obj, b'\xff')
# CRASHES delattrstring(obj, NULL)
Expand Down Expand Up @@ -297,7 +297,7 @@ def test_object_setitem(self):
self.assertRaises(SystemError, setitem, {}, 'a', NULL)
self.assertRaises(IndexError, setitem, [], 1, 5)
self.assertRaises(TypeError, setitem, [], 'a', 5)
self.assertRaises(TypeError, setitem, (), 1, 5)
self.assertRaises(NotWriteableError, setitem, (), 1, 5)
self.assertRaises(SystemError, setitem, NULL, 'a', 5)

def test_mapping_setitemstring(self):
Expand Down
10 changes: 5 additions & 5 deletions Lib/test/test_descr.py
Original file line number Diff line number Diff line change
Expand Up @@ -1076,7 +1076,7 @@ class SubType(types.ModuleType):

class MyInt(int):
__slots__ = ()
with self.assertRaises(TypeError):
with self.assertRaises(NotWriteableError):
(1).__class__ = MyInt

class MyFloat(float):
Expand All @@ -1091,17 +1091,17 @@ class MyComplex(complex):

class MyStr(str):
__slots__ = ()
with self.assertRaises(TypeError):
with self.assertRaises(NotWriteableError):
"a".__class__ = MyStr

class MyBytes(bytes):
__slots__ = ()
with self.assertRaises(TypeError):
with self.assertRaises((TypeError, NotWriteableError)):
b"a".__class__ = MyBytes

class MyTuple(tuple):
__slots__ = ()
with self.assertRaises(TypeError):
with self.assertRaises(NotWriteableError):
().__class__ = MyTuple

class MyFrozenSet(frozenset):
Expand Down Expand Up @@ -4082,7 +4082,7 @@ class D(C):

try:
list.__bases__ = (dict,)
except TypeError:
except NotWriteableError:
pass
else:
self.fail("shouldn't be able to assign to list.__bases__")
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_type_aliases.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def test_errors(self):

class TypeAliasTypeTest(unittest.TestCase):
def test_immutable(self):
with self.assertRaises(TypeError):
with self.assertRaises(NotWriteableError):
TypeAliasType.whatever = "not allowed"

def test_no_subclassing(self):
Expand Down
4 changes: 2 additions & 2 deletions Lib/test/test_type_annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ def test_annotations_getset_raises(self):
# builtin types don't have __annotations__ (yet!)
with self.assertRaises(AttributeError):
print(float.__annotations__)
with self.assertRaises(TypeError):
with self.assertRaises(NotWriteableError):
float.__annotations__ = {}
with self.assertRaises(TypeError):
with self.assertRaises(NotWriteableError):
del float.__annotations__

# double delete
Expand Down
4 changes: 2 additions & 2 deletions Lib/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2388,7 +2388,7 @@ def no_type_check(arg):
no_type_check(obj)
try:
arg.__no_type_check__ = True
except TypeError: # built-in classes
except NotWriteableError: # built-in classes
pass
return arg

Expand Down Expand Up @@ -2507,7 +2507,7 @@ class Other(Leaf): # Error reported by type checker
"""
try:
f.__final__ = True
except (AttributeError, TypeError):
except (AttributeError, TypeError, NotWriteableError):
# Skip the attribute silently if it is not writable.
# AttributeError happens if the object has __slots__ or a
# read-only property, TypeError if it's a builtin class.
Expand Down
2 changes: 1 addition & 1 deletion Lib/unittest/suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def _handleClassSetUp(self, test, result):
failed = False
try:
currentClass._classSetupFailed = False
except TypeError:
except NotWriteableError:
# test may actually be a function
# so its class will be a builtin-type
pass
Expand Down