sarugaku / resolvelib

Resolve abstract dependencies into concrete ones
ISC License
142 stars 31 forks source link

Consumer passes in a prepare method which is called over backtrack causes #96

Open jbylund opened 2 years ago

jbylund commented 2 years ago

Add a prepare attribute to the Resolution object which is called on backtrack causes before passing that to _get_preference. This allows providers to operate over a processed version of backtrack_causes without having to implement a cache consumer side (which can be "yucky").

jbylund commented 2 years ago

@notatallshaw this is the other possibility I mentioned. Let me know if you think this would mesh well with your ideas for backtracking in the future?

notatallshaw commented 2 years ago

This approach LGTM if maintainers want the logic of processing the causes to remain on the downstream library side.

And I continue to really prefer avoiding a cache that depends on the ids of mutable objects (even if they are carefully used).

I guess let's just see what maintainers think.

uranusjr commented 2 years ago

I think #93 would supercede this now?

jbylund commented 2 years ago

I think #93 would supercede this now?

My opinion is that this option would allow for:

uranusjr commented 2 years ago

Sounds like a provider function is also a fit for those reasons? If the consumer wishes, it can simply implement the function to return a set, or whatever built-in or custom type that suits the need.

jbylund commented 2 years ago

Sounds like a provider function is also a fit for those reasons? If the consumer wishes, it can simply implement the function to return a set, or whatever built-in or custom type that suits the need.

But I think we need this "hook" to allow the provider to inject such a function?

jbylund commented 2 years ago

The pip side of this change would be this.