Repository navigation
gh-73055: Set class module to caller module in ABCMeta.__new__ #14126
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
alegonz
wants to merge
4
commits into
python:main
from
alegonz:fix/add-caller-module-to-class-in-ABCMeta.__new__
Closed
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
fa9f009
test_abc.py: Added tests for __module__ attribute in dynamically defi…
alegonz ccdf280
Set __module__ attribute of created class to caller frame in ABCMeta.…
alegonz 93f52bb
test_abc.py: Added tests for pickling of instances of dynamically def…
alegonz e3f8e02
Temporarily added a script for benchmarking ABCMeta. This script will…
alegonz 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
Prev
Previous commit
Temporarily added a script for benchmarking ABCMeta. This script will…
… be removed in a future commit.
- Loading branch information
commit e3f8e026f77bdbe2f6d91bbb05df1a0268271078
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| import csv | ||
| import timeit | ||
|
|
||
|
|
||
| def median(x): | ||
| n = len(x) | ||
| middle = n // 2 | ||
| sx = sorted(x) | ||
| if n % 2: | ||
| return sx[middle] | ||
| else: | ||
| return (sx[middle] + sx[middle - 1]) / 2 | ||
|
|
||
|
|
||
| implementations = {"C": "import abc", | ||
| "Py": "import _py_abc"} | ||
| statements = { | ||
| "C": { | ||
| "master": "abc.ABCMeta('ABC_C', (), {'__module__': __name__})", | ||
| "fix": "abc.ABCMeta('ABC_C', (), {})" | ||
| }, | ||
| "Py": { | ||
| "master": "_py_abc.ABCMeta('ABC_Py', (), {'__module__': __name__})", | ||
| "fix": "_py_abc.ABCMeta('ABC_Py', (), {})" | ||
| } | ||
| } | ||
|
|
||
| repeat = 50000 | ||
| number = 1 | ||
|
|
||
| data = {} | ||
| for imp, setup in implementations.items(): | ||
| for branch, stmt in statements[imp].items(): | ||
| print("timing {} - {} implementation of ABCMeta...".format(branch, imp)) | ||
| times = timeit.repeat(stmt, setup=setup, repeat=repeat, number=number) | ||
| header = "{}_{}".format(branch, imp) | ||
| data[header] = times | ||
|
|
||
|
|
||
| for imp in implementations: | ||
| t_master = median(data["master_{}".format(imp)]) | ||
| t_fix = median(data["fix_{}".format(imp)]) | ||
|
|
||
| absdiff = t_fix - t_master | ||
| slowdown = (t_fix - t_master) / t_master | ||
|
|
||
| print("{} implementation".format(imp)) | ||
| print(" Absolute difference:", 1000 * absdiff, "ms") | ||
| print(" Slowdown:", 100 * slowdown, "%") | ||
|
|
||
| print("Dumping to CSV file...") | ||
| with open("abc_bench.csv", "w") as csvfile: | ||
| writer = csv.writer(csvfile) | ||
| data = [[header] + times for header, times in data.items()] | ||
| for row in zip(*data): | ||
| writer.writerow(row) | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file was temporarily added for sharing purposes. It will removed in a future commit.