-
-
Notifications
You must be signed in to change notification settings - Fork 32k
gh-106016: Support customizing of module attributes access with __setattr__/__delattr__ (PEP 726) #108261
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
gh-106016: Support customizing of module attributes access with __setattr__/__delattr__ (PEP 726) #108261
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
a840465
gh-106016: Support customizing of module attributes access with __set…
skirpichev 3e78225
Update Doc/reference/datamodel.rst
skirpichev 0a8cec6
Update Doc/reference/datamodel.rst
skirpichev 2904f50
Update Doc/reference/datamodel.rst
skirpichev bce1667
Drop PyErr_Clear()
skirpichev bcafd0d
move delattr/setattr declarations
skirpichev 0740efb
m -> mod
skirpichev 74c3d13
Check PyObject_CallFunctionObjArgs return value
skirpichev 83c4c50
Document changes in the "Other Language Changes" section
skirpichev 7fe6a06
Use PyDict_GetItemRef instead of PyDict_GetItemWithError
skirpichev 47d93ce
Move test modules to Lib/test/test_module/
skirpichev f3f796d
Avoid ret variable
skirpichev f971a22
+Py_DECREF
skirpichev 68eefbd
Reorder setattr/delattr paths
skirpichev 048d8bf
Merge branch 'main' into module-setdelattr
skirpichev 058412e
Apply suggestions from code review
skirpichev 49c82c5
Update Lib/test/test_module/__init__.py
skirpichev 280fc0e
Merge branch 'main' into module-setdelattr
skirpichev dafc546
Merge branch 'main' into module-setdelattr
skirpichev 9dcacaf
Merge branch 'main' into module-setdelattr
skirpichev cd0e4be
Mention PEP in docs, like PEP 562
skirpichev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 @@ | ||
foo = 1 | ||
__delattr__ = "Oops" |
This file contains hidden or 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,4 @@ | ||
foo = 1 | ||
|
||
def __delattr__(): | ||
"Bad function signature" |
This file contains hidden or 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 @@ | ||
foo = 1 | ||
__setattr__ = "Oops" |
This file contains hidden or 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,4 @@ | ||
foo = 1 | ||
|
||
def __setattr__(): | ||
"Bad function signature" |
This file contains hidden or 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,6 @@ | ||
foo = 1 | ||
|
||
def __delattr__(name): | ||
if name == 'foo': | ||
raise AttributeError("Read-only attribute") | ||
del globals()[name] |
This file contains hidden or 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,6 @@ | ||
foo = 1 | ||
|
||
def __setattr__(name, value): | ||
if name == 'foo': | ||
raise AttributeError("Read-only attribute") | ||
globals()[name] = value |
2 changes: 2 additions & 0 deletions
2
Misc/NEWS.d/next/Core and Builtins/2023-08-22-09-57-59.gh-issue-106016.lpbUq8.rst
This file contains hidden or 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 support for module ``__setattr__`` and ``__delattr__``. Patch by Sergey | ||
B Kirpichev. | ||
skirpichev marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.