[mypyc] Fix order of dispatch type checking in singledispatch functio… #95
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.
…ns (python#10844)
Add a test that makes sure that our implementation goes up the MRO of
the dispatch type and uses the registered implementation that comes
first, instead of going through implementations in the reverse order.
When creating a dispatch function for a singledispatch function, avoid
checking any classes before we've checked all of their subclasses. That
makes sure we use the implementation with the dispatch type that appears
first in the actual argument's type's MRO, which is what the standard
library implementation of singledispatch does (it goes up the argument's
MRO, looking for classes that have registered implementations associated
with them).
Add a test to reproduce the bug in the class sorting implementation
mentioned in
python#10844 (comment).
Improve the sorting of classes to:
there are multiple related classes (see
testMultipleRelatedClassesBeingRegistered for an example of this)
The one use of Iterable was removed in the previous commit, so this is
unnecessary.
Change the sorting of classes that we use when generating dispatch
functions to use topological sort on a graph made up of the classes with
edges pointing from subclasses to the classes on their MRO.
This also modifies the signature of topsort to take any type for the
vertices of the graph.
Use a dictionary comprehension to make the graph creation nicer.
Have you read the Contributing Guidelines?
(Once you have, delete this section. If you leave it in, your PR may be closed without action.)
Description
(Explain how this PR changes mypy.)
Test Plan
(Write your test plan here. If you changed any code, please provide us with clear instructions on how you verified your changes work.)