-
-
Notifications
You must be signed in to change notification settings - Fork 294
Optimize _compute_mro()
#2187
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
Optimize _compute_mro()
#2187
Conversation
clean_duplicates_mro()
_compute_mro()
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #2187 +/- ##
==========================================
+ Coverage 92.61% 92.63% +0.02%
==========================================
Files 94 94
Lines 10814 10818 +4
==========================================
+ Hits 10015 10021 +6
+ Misses 799 797 -2
Flags with carried forward coverage won't be shown. Click here to find out more.
|
@@ -133,24 +133,24 @@ def clean_typing_generic_mro(sequences: list[list[ClassDef]]) -> None: | |||
bases_mro.pop(position_in_inferred_bases) | |||
|
|||
|
|||
def clean_duplicates_mro(sequences, cls, context): | |||
def clean_duplicates_mro( | |||
sequences: Iterable[Iterable[ClassDef]], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yield from baseobj.bases |
This makes this SuccesfulInferenceResult
although I wonder if ClassDef.bases
could be narrowed down. I'd be okay with making this ClassDef
for now and fixing later if necessary, but note that this will add one more mypy
warning after _inferred_bases
gets its signature typed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep. However, Pyright also says it could be ClassDef
due to this:
astroid/astroid/nodes/scoped_nodes/scoped_nodes.py
Lines 2803 to 2804 in feafcb8
if not baseobj.hide: | |
yield baseobj |
Let's wait until we're ready to type this all together.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah of course, the bases
line just broadens the type (perhaps/probably incorrectly)
Description
clean_duplicates_mro()
_compute_mro()
for "builtins.object"Performance improvement is more noticeable in projects making heavy use of inheritance. For the project
music21
from the pylint primer:Benchmark
main
PR
That's ~2s saved out of ~160s, or 1.25%.