From ad70174bfca58d7e57974011ef543e4747d07f03 Mon Sep 17 00:00:00 2001 From: Pradyun Gedam Date: Wed, 21 Nov 2018 14:23:48 +0530 Subject: [PATCH] Minor cleanups to format_control.py --- src/pip/_internal/models/format_control.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/pip/_internal/models/format_control.py b/src/pip/_internal/models/format_control.py index 126519827cc..971a3914ced 100644 --- a/src/pip/_internal/models/format_control.py +++ b/src/pip/_internal/models/format_control.py @@ -3,20 +3,22 @@ from pip._internal.utils.typing import MYPY_CHECK_RUNNING if MYPY_CHECK_RUNNING: - from typing import Optional, Set # noqa: F401 + from typing import Optional, Set, FrozenSet # noqa: F401 class FormatControl(object): - """A helper class for controlling formats from which packages are installed. - If a field is falsy, it isn't set. If it is {':all:'}, it should match all - packages except those listed in the other field. Only one field can be set - to {':all:'} at a time. The rest of the time exact package name matches - are listed, with any given package only showing up in one field at a time. + """Helper for managing formats from which a package can be installed. """ + def __init__(self, no_binary=None, only_binary=None): # type: (Optional[Set], Optional[Set]) -> None - self.no_binary = set() if no_binary is None else no_binary - self.only_binary = set() if only_binary is None else only_binary + 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): return self.__dict__ == other.__dict__ @@ -52,6 +54,7 @@ def handle_mutual_excludes(value, target, other): target.add(name) def get_allowed_formats(self, canonical_name): + # type: (str) -> FrozenSet result = {"binary", "source"} if canonical_name in self.only_binary: result.discard('source') @@ -64,6 +67,7 @@ def get_allowed_formats(self, canonical_name): return frozenset(result) def disallow_binaries(self): + # type: () -> None self.handle_mutual_excludes( ':all:', self.no_binary, self.only_binary, )