code: def try_to_replace(self, provider, other, problems):
          
          rlist = self.reqts[other]
          unmatched = set()
          for s in rlist:
              matcher = self.get_matcher(s)
              if not matcher.match(provider.version):
                  unmatched.add(s)
          if unmatched:
              # can't replace other with provider
              problems.add(('cantreplace', provider, other,
                            frozenset(unmatched)))
              result = False
          else:
              # can replace other with provider
              self.remove_distribution(other)
              del self.reqts[other]
              for s in rlist:
                  self.reqts.setdefault(provider, set()).add(s)
              self.add_distribution(provider)
              result = True
          return result
docs: Attempt to replace one provider with another. This is typically used
          when resolving dependencies from multiple sources, e.g. A requires
          (B >= 1.0) while C requires (B >= 1.1).
  
          For successful replacement, ``provider`` must meet all the requirements
          which ``other`` fulfills.
  
          :param provider: The provider we are trying to replace with.
          :param other: The provider we're trying to replace.
          :param problems: If False is returned, this will contain what
                           problems prevented replacement. This is currently
                           a tuple of the literal string 'cantreplace',
                           ``provider``, ``other``  and the set of requirements
                           that ``provider`` couldn't fulfill.
          :return: True if we can replace ``other`` with ``provider``, else
                   False.