-
-
Notifications
You must be signed in to change notification settings - Fork 31k
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
add program passed as string to dis module. #88571
Comments
python dis module should have a program passed in as string. Currently, you can do this: would be convenient like this: these changes seem to be working. |
I checked https://docs.python.org/3/library/dis.html and there is no mention of dis having a command-line interface. This suggests that _test is likely present only for testing the module, not for using it. This was common a couple of decades ago before we had unittests. If _test were considered obsolete, it could be removed. By suggesting that the command line interface by upgraded, I suspect that you are implicitly suggesting that it be considered 'official'. If so, that '_test' should become '_main' (where the underscore leaves it out of __all__), and the CLI documented as in other modules with a CLI. (I am not up on the details and policy around this issue.) It may be appropriate to start a discussion of python-ideas. |
What is unusual, I think, for a CLI test function is that it requires a passed in argument. As a sanity-check test, 'python -m dis' could (should) disassemble itself. Perhaps there once were some true tests that were moved to unittests. (I started IDLE unittests by doing this with module test functions.) If you know git, you could check the history and checkin messages. |
Huh, that's actually weird that the "exisisting command line interface" (quotes because it was added as a test) isn't official. I've found it to be convinient as a newcomer to the cpython codebase.
git blame shows the commit hash is 0956689, which is for bpo: https://bugs.python.org/issue18538 "python -m dis now uses argparse". The Misc/HISTORY file references the change in section "What's New in Python 3.4.0 Alpha 3?" Regardless of the cli being official, personally I think, it's a good feature to add. But also, maybe I should start a discussion in python-ideas about making it official? |
Yup, originally it was added 2 decades ago (in 2000) originally as a test: 1fdae12 |
removing _test: CCLDArjun@8b3b8cc does not break dis tests. |
I often use the command-line interface of dis, ast, and sometimes tokenize modules. They are mature enough and not only for self-testing. If they are not documented, we need to document them. Since they read from stdin by default (no need to specify /dev/stdin or CON explicitly) I never needed the -c option. It would not be particularly useful in any case because Python code is usually multi-line. BTW sometimes I want to implement GUI for these modules in IDLE. |
I suspect the only reason the dis CLI isn't documented is because it's been around for so long (22 years!) that nobody previously noticed it was missing: 1fdae12 Folks then either didn't know about it, or already knew how to use it. Even the migration to use argparse was a code cleanup from a user that happened to be reading the module source code and noticed that it didn't already do so: https://bugs.python.org/issue18538 I can see value in supporting |
Neither of tokenize, ast or symtable modules support passing the source string as argument. If add this feature in the dis module, we will need to add it in all other modules with similar CLI. I do not think it is practical. You always can pass the source string via stdin. And you do not even need to pass /dev/stdin as argument, stdin is the default. I usually use it with rlwrap. It allows to use some editing and history.
I propose to close this issue and open a new issue for documenting the CLI of the dis module. |
I suggest to close this issue. |
We documented the If we want to support inline arguments for dis, we should also support it for tokenize, ast and symtable in one go and this should warrant a DPO thread: https://discuss.python.org/c/ideas/6. Closing as |
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: