forked from python/cpython
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pythongh-121654: Add PyType_Freeze() function
- Loading branch information
Showing
11 changed files
with
100 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from test.support import import_helper | ||
import unittest | ||
|
||
_testcapi = import_helper.import_module('_testcapi') | ||
|
||
|
||
class TypeTests(unittest.TestCase): | ||
def test_freeze(self): | ||
# test PyType_Freeze() | ||
type_freeze = _testcapi.type_freeze | ||
|
||
class MyType: | ||
pass | ||
MyType.attr = "mutable" | ||
|
||
type_freeze(MyType) | ||
with self.assertRaises(TypeError): | ||
MyType.attr = "immutable" | ||
|
||
# PyType_Freeze() requires base classes to be immutable | ||
class Mutable: | ||
"mutable base class" | ||
pass | ||
class MyType2(Mutable): | ||
pass | ||
with self.assertRaises(TypeError): | ||
type_freeze(MyType2) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
2 changes: 2 additions & 0 deletions
2
Misc/NEWS.d/next/C_API/2024-07-30-14-40-08.gh-issue-121654.tgGeAl.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Add :c:func:`PyType_Freeze` function to make a type immutable. Patch by | ||
Victor Stinner. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2510,3 +2510,5 @@ | |
added = '3.14' | ||
[function.PyIter_NextItem] | ||
added = '3.14' | ||
[function.PyType_Freeze] | ||
added = '3.14' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.