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
PR for #570: disambiguate the name 'ast' #579
Conversation
@lieryan I now see how to explain the merits of this PR. Rope's old code violates two design principles:
PR #572: fixed a violation of Principle 2. This PR fixes violations of both principles. Problems with Rope's legacy code The present code misuses the name
Future refactorings Let's consider how this PR will simplify future refactorings. Case 1: Enhance ast.parse. PR #577 is a stopgap. We desire a version of ast.parse that can handle all python versions that Rope supports. This PR encapsulates/wraps astutils.parse. If parse ever changes, none of Rope's code will change (except for astutils.py itself). For example, we might create a separate module containing only the new parse function. Only astutils will know of that module. Case 2: Replace ast nodes with wrapped nodes. In the (unlikely) event that Rope will ever want to use some wrapped version of ast.AST, this PR's code will simplify that change. Just replace ast with (say) ast2. This PR makes that replacement safe. There will be no false matches with functions in astutils. Summary Rope's legacy code violates two design principles. This PR fixes both. Misusing the |
@lieryan I awoke just now, in the middle of the night, understanding what you have been trying to do, namely have Fair enough, but the name clash between I am willing to create another PR with the following changes:
What do you think? |
@lieryan When I awoke the second time this morning I saw there is an even simpler way:
Advantages
@lieryan Your comments, please. |
@lieryan There is another confusion that should be addressed. At present, I recommend moving three functions now in
|
@lieryan Perhaps you wonder how I can confidently make the suggestions I am making. Leo makes global reasoning straightforward:
It's that easy. Update: And it's way easy to move from file to file. No need to open files in a text editor. |
You should wake up the third time again to come up with something even more simplerer 😜 I don't agree that the "name clash", so to speak is a major issue though, or an issue at all. As people wiser than me said "Namespaces are one honking good idea", the names live in different namespaces, so there isn't really a name clash per se, the names aren't clashing. If you really feel strongly about the issue, I don't mind changing it, but I disagree that renaming it to astutils/astwrappers/etc is an improvement. That There are really only a few things that really bothers me with the current
As for the other issue, I don't think removing I suggest just turning off flakes for this file. And I don't know if it'll work, but maybe we can define |
I think what we can do with the import of That way, even without looking at the imports, the code that uses rope ast will always unambiguously look different than code that uses stdlib Code that uses rope's ast will look like: |
See #570 for the notable changes.
Other changes