bpo-30152: Reduce the number of imports for argparse. (#1269)

This commit is contained in:
Serhiy Storchaka 2017-09-26 00:55:55 +03:00 committed by GitHub
parent f1502d097c
commit 81108375d9
8 changed files with 59 additions and 49 deletions

View file

@ -1,7 +1,5 @@
import sys
from types import MappingProxyType, DynamicClassAttribute
from functools import reduce
from operator import or_ as _or_
# try _collections first to reduce startup cost
try:
@ -744,11 +742,10 @@ class Flag(Enum):
def __invert__(self):
members, uncovered = _decompose(self.__class__, self._value_)
inverted_members = [
m for m in self.__class__
if m not in members and not m._value_ & self._value_
]
inverted = reduce(_or_, inverted_members, self.__class__(0))
inverted = self.__class__(0)
for m in self.__class__:
if m not in members and not (m._value_ & self._value_):
inverted = inverted | m
return self.__class__(inverted)