PR: Simplify Rope's class hierarchy#664
Closed
edreamleo wants to merge 25 commits intopython-rope:masterfrom
edreamleo:ekr-abstract-predicates
Closed
PR: Simplify Rope's class hierarchy#664edreamleo wants to merge 25 commits intopython-rope:masterfrom edreamleo:ekr-abstract-predicates
edreamleo wants to merge 25 commits intopython-rope:masterfrom
edreamleo:ekr-abstract-predicates
Conversation
5 tasks
Contributor
Author
|
@lieryan I am going to close this PR. I'll use ekr-fork-rope2 to work on the Theory of Operation without bothering you. |
This was referenced Feb 26, 2023
Contributor
Author
|
@lieryan I am going to reopen this PR as a draft. This PR is one of three approaches I am considering: PR #664 (This PR):Replace PRs #664 and #677 both work. PR #677 has zero impact on performance. The other two PRs likely have negligible impact on performance, but more testing is needed. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR collapses the complexity of several type-inference classes:
Abstractclasses with one new arg toPyObject.__init__.PyObjectorPyDefinedObject.PyDefinedObjectis a subclass ofPyObject.The annotation,
Union[PyObject, PyDefinedObject], can be replaced byPyObject.Note: The
ekr-mypy-single-inheritancebranch (PR #665) annotates this branch, with the usual changes torope.base.astneeded to let mypy do complete checking. Those checks found three missing functions that have now been moved from twoAbstractclasses into the appropriate classes inpyobjects.py.Summary of the changes, in the order they occurred:
get_base_typeandget_unknownfunctions inpyobjects.py.Abstractclasses.AbstractClass,AbstractFunction, andAbstractModuleclasses.Step 1: Simplify the
get_base_typeandget_unknownfunctionsget_base_typeandget_unknownfunctions inpyobjects.py.PyObject._get_base_typestatic method.Step 2: Remove most methods from the
AbstractclassesAbstractclasses, retaining 3 methods found nowhere else.get_superclassesfrom theBuiltinObjectto its base class,BuiltinClass.With this change,
BuiltinObjecthas the same form as the threeAbstractclasses.Step 3: Remove all three Abstract classes
rope/base/utils/predicates.py.isinstance(obj, Abstract*)withis_abstract_*(obj).Note: Neither the
get_base_typenor theget_unknownfunction requires theAbstractclasses.Abstractclasses entirely.Discussion:
Abstractclasses as markers.The legacy pattern is
if isinstance(obj, AbstractX):The new pattern is
if is_abstract_x(obj):. This pattern is shorter, but is less explicit.Abstractclasses help init theirPyObjectbase classes, but Part 4 shows that this is "faux help".The formerly "abstract" classes need only add one new arg when instantiating
PyObject.Step 4: Use single inheritance for all type-inference classes
This step was unexpectedly very easy.
PyDefinedObjectnow hasPyObjectas its only base class.The
PyObjectannotation can replaceUnion[PyObject, PyDefinedObject].PyDefinedObjectas their only base class:po.PyClass,po.PyComprehension,po.PyFunction,po._PyModule.pod.PyFunction,pod.PyClass,pod.PyComprehension