# Buggy code
def _group_constraints(self, constraints):
    """
    Groups constraints (remember, InstallRequirements!) by their key name,
    and combining their SpecifierSets into a single InstallRequirement per
    package.  For example, given the following constraints:

        Django<1.9,>=1.4.2
        django~=1.5
        Flask~=0.7

    This will be combined into a single entry per package:

        django~=1.5,<1.9,>=1.4.2
        flask~=0.7

    """
    for _, ireqs in full_groupby(constraints, key=_dep_key):
        ireqs = list(ireqs)
        editable_ireq = first(ireqs, key=lambda ireq: ireq.editable)
        if editable_ireq:
            yield editable_ireq  # ignore all the other specs: the editable one is the one that counts
            continue

        ireqs = iter(ireqs)
        # deepcopy the accumulator so as to not modify the self.our_constraints invariant
        combined_ireq = copy.deepcopy(next(ireqs))
        combined_ireq.comes_from = None
        for ireq in ireqs:
            # NOTE we may be losing some info on dropped reqs here
            combined_ireq.req.specifier &= ireq.req.specifier
            combined_ireq.constraint &= ireq.constraint
            # Return a sorted, de-duped tuple of extras
            combined_ireq.extras = tuple(
                sorted(set(tuple(combined_ireq.extras) + tuple(ireq.extras)))
            )
        yield combined_ireq


# Traceback (TypeError)
$ venv/bin/pip-sync dev-requirements.txt
Traceback (most recent call last):
File "venv/bin/pip-sync", line 11, in <module>
sys.exit(cli())
File "venv/lib64/python3.6/site-packages/click/core.py", line 722, in __call__
return self.main(*args, **kwargs)
File "venv/lib64/python3.6/site-packages/click/core.py", line 697, in main
rv = self.invoke(ctx)
File "venv/lib64/python3.6/site-packages/click/core.py", line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "venv/lib64/python3.6/site-packages/click/core.py", line 535, in invoke
return callback(*args, **kwargs)
File "venv/lib64/python3.6/site-packages/piptools/scripts/sync.py", line 74, in cli
install_flags=install_flags))
File "venv/lib64/python3.6/site-packages/piptools/sync.py", line 159, in sync
for ireq in sorted(to_install):
TypeError: '<' not supported between instances of 'InstallRequirement' and 'InstallRequirement'

# Fixed code
def _group_constraints(self, constraints):
    """
    Groups constraints (remember, InstallRequirements!) by their key name,
    and combining their SpecifierSets into a single InstallRequirement per
    package.  For example, given the following constraints:

        Django<1.9,>=1.4.2
        django~=1.5
        Flask~=0.7

    This will be combined into a single entry per package:

        django~=1.5,<1.9,>=1.4.2
        flask~=0.7

    """
    for _, ireqs in full_groupby(constraints, key=key_from_ireq):
        ireqs = list(ireqs)
        editable_ireq = first(ireqs, key=lambda ireq: ireq.editable)
        if editable_ireq:
            yield editable_ireq  # ignore all the other specs: the editable one is the one that counts
            continue

        ireqs = iter(ireqs)
        # deepcopy the accumulator so as to not modify the self.our_constraints invariant
        combined_ireq = copy.deepcopy(next(ireqs))
        combined_ireq.comes_from = None
        for ireq in ireqs:
            # NOTE we may be losing some info on dropped reqs here
            combined_ireq.req.specifier &= ireq.req.specifier
            combined_ireq.constraint &= ireq.constraint
            # Return a sorted, de-duped tuple of extras
            combined_ireq.extras = tuple(
                sorted(set(tuple(combined_ireq.extras) + tuple(ireq.extras)))
            )
        yield combined_ireq