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
staticmethod and classmethod are ignored when disassemble class #70920
Comments
Though the documentation tells when disassembling a class, it disassembles all methods for dis.dis, but staticmethod and classmethod are ignored. I don't know whether this is intended. I write to patch to add staticmethod and classmethod. But unfortunately when I write tests, one unrelated test fails and I cannot figure out why. |
Though don't know why but simply replace %-4d with %3d in dis_bug708901 can fix the test. I updated the patch so all the tests pass and then I'll spend some time figuring out why. |
After researching the code, I think changing ' %-4d' to '%3d' in dis_bug708901 is right. Since I added some some lines and the lineno of test_bug708901 has arrived at 100+ and the leading space should not be there. According to the code of dis.dis, the right format string should be '%3d'. Not only test_bug708901, all the other ' %-4d' should be changed to '%3d'. If we add 1000+ lines at the head of the file, then all the ' %-4d' format string will lead to test failures. I update my patch. |
The code and test changes in the latest patch look good to me. For documentation, I suggest updating https://docs.python.org/3/library/dis.html#dis.dis to:
|
I update the documentation. Learning from devguide, the change of whatsnew is the committer's work. ;) |
If this is new feature, perhaps the docs need the versionchanged directive. Otherwise the patch should be applied to all maintained branches. Added other comments on Rietveld. |
New changeset b114a0650c44 by Serhiy Storchaka in branch '3.5': New changeset e0816ce68952 by Serhiy Storchaka in branch 'default': New changeset 16a27e38e9b5 by Serhiy Storchaka in branch '2.7': |
Thanks for your comments Serhiy. I update the patch according to your comments. Actually I don't think this is a new feature. Maybe staticmethod and classmethod are just forgotten. As for separate tests for staticmethod and classmethod, I think they are not needed for this patch since right now we can use dis.dis to disassemble them explicitly. Only when dis.dis a class they are missing. But since there are no tests for them, adding tests for them is good. |
LGTM. Nick, do you consider this as a new feature, or as a fix? |
Looking at the history of the dis module, I'd now class this as a bug fix for 3.5+ - it looks like dis.dis gained the ability to disassemble static and class methods as a side-effect of the removal of bound methods in Python 3 (see https://hg.python.org/cpython/rev/48af6375207e ) but because it was a side effect, the additional changes needed to also handle them when disassembling a class were missed. |
New changeset d14ea3964590 by Serhiy Storchaka in branch '3.5': New changeset f96fec10cf25 by Serhiy Storchaka in branch 'default': |
Thank you for your contribution Xiang Zhang. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: