sarugaku / resolvelib

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

Let downstream library to define causes object #99

Closed notatallshaw closed 2 years ago

notatallshaw commented 2 years ago

Addresses comments made in https://github.com/sarugaku/resolvelib/pull/93#issuecomment-970470701

Provider now has a causes method that allows it to define what the causes object looks like.

The returned object must implement the following:

For example if would be possible to implement the method like so to preserve the existing behavior (would work on Python 2.7 to 3.10):

def causes(self, causes):
    return [i for c in causes for i in c.information]

There is an accompanying pip PR (https://github.com/pypa/pip/pull/10732) that leverages this new interface to resolve the performance issues described in https://github.com/pypa/pip/pull/10621

Need some hints / help defining a better type than "Any" for "causes" if that matters.

notatallshaw commented 2 years ago

There are some architectural differences between the way I've implemented this and how Requirement and Candidate work.

@uranusjr if you get a chance some time let me know if this is what you were thinking or if I missed the shot and need to make some correction.

notatallshaw commented 2 years ago

Upon some further thinking this approach is type unsafe, I need to study how other objects are implemented a bit better first.