import operator

from pip._vendor.packaging.utils import canonicalize_name

from pip._internal.exceptions import CommandError
from pip._internal.utils.typing import MYPY_CHECK_RUNNING

if MYPY_CHECK_RUNNING:
    from typing import Optional, Set, FrozenSet


class FormatControl(object):
    """Helper for managing formats from which a package can be installed.
    """

    __slots__ = ["no_binary", "only_binary"]

    def __init__(self, no_binary=None, only_binary=None):
        # type: (Optional[Set[str]], Optional[Set[str]]) -> None
        if no_binary is None:
            no_binary = set()
        if only_binary is None:
            only_binary = set()

        self.no_binary = no_binary
        self.only_binary = only_binary

    def __eq__(self, other):
        # type: (object) -> bool
        if isinstance(other, self.__class__):
            if self.__slots__ == other.__slots__:
                attr_getters = [operator.attrgetter(attr)
                                for attr in self.__slots__]
                return all(getter(self) == getter(other)
                           for getter in attr_getters)

        return False

    def __ne__(self, other):
        # type: (object) -> bool
        return not self.__eq__(other)

    def __repr__(self):
        # type: () -> str
        return "{}({}, {})".format(
            self.__class__.__name__,
            self.no_binary,
            self.only_binary
        )

    @staticmethod
    def handle_mutual_excludes(value, target, other):
        # type: (str, Set[str], Set[str]) -> None
        if value.startswith('-'):
            raise CommandError(
                "--no-binary / --only-binary option requires 1 argument."
            )
        new = value.split(',')
        while ':all:' in new:
            other.clear()
            target.clear()
            target.add(':all:')
            del new[:new.index(':all:') + 1]
            # Without a none, we want to discard everything as :all: covers it
            if ':none:' not in new:
                return
        for name in new:
            if name == ':none:':
                target.clear()
                continue
            name = canonicalize_name(name)
            other.discard(name)
            target.add(name)

    def get_allowed_formats(self, canonical_name):
        # type: (str) -> FrozenSet[str]
        result = {"binary", "source"}
        if canonical_name in self.only_binary:
            result.discard('source')
        elif canonical_name in self.no_binary:
            result.discard('binary')
        elif ':all:' in self.only_binary:
            result.discard('source')
        elif ':all:' in self.no_binary:
            result.discard('binary')
        return frozenset(result)

    def disallow_binaries(self):
        # type: () -> None
        self.handle_mutual_excludes(
            ':all:', self.no_binary, self.only_binary,
        )

@@ -805,16 +805,20 @@
      if 
+not 
 isinstan
@@ -844,24 +844,67 @@
 ass__):%0A    
+        return NotImplemented%0A            %0A
         if s
@@ -917,17 +917,17 @@
 slots__ 
-=
+!
 = other.
@@ -953,160 +953,86 @@
     
-    attr_getters = %5Boperator.attrgetter(attr)%0A                                for attr in self.__slots__%5D%0A                return all(ge
+return NotImplemented%0A%0A        return all(%0A            geta
 tt
-e
 r(self
+, k
 ) == get
 ter(
@@ -1031,95 +1031,68 @@
  get
+at
 t
-e
 r(other
-)%0A                           for getter in attr_getters)%0A%0A        return False
+, k)%0A            for k in self.__slots__%0A        )
 %0A%0A  

Update src/pip/_internal/models/format_control.py