-
Notifications
You must be signed in to change notification settings - Fork 2
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
feat: prioritize specialized providers over generic #77
Conversation
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.
Implementation looks ok, but there is a whole bunch of tests missing for generics with multiple typevars and various partial specializations.
src/sciline/pipeline.py
Outdated
if _is_compatible_type_tuple(requested, args) | ||
), | ||
) | ||
matches = match_groups[min(match_groups.keys(), default=0)] |
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.
I found the use of defaultdict
a bit confusing when reading this.
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.
The use of defaultdict comes from the groupby
, for all intents and purposes it could have been a regular dict. In line 473 the providers with the fewest TypeVar
arguments are passed on and the rest are dropped.
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.
whole bunch of tests missing for generics with multiple typevars and various partial specializations.
Yeah you're right. I'll fix that.
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.
My point is: If there are no matches, then you would get a KeyError
here, unless you use defaultdict
, which is the wrong exception type, right?
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 okay I see, the logic should be made clearer there, it's just a fluke that we don't get a bug because match_groups
happens to be defaultdict
.
c84ad58
to
fb43e78
Compare
Fixes #69
A type tuple
a
is considered more "special" than a type tupleb
if the number ofTypeVar
s ina
is lower than inb
.