From 115c90afb868384505ad5525d6e5a36d319aa2ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Langa?= Date: Wed, 18 Jan 2017 14:45:19 -0800 Subject: [PATCH] Fix if statements with ambiguously indented bodies Since this was related to the same lines in conditions, also fixed binary operators on line beginnings. --- python2/typing.py | 29 +++++++++++++++++++---------- src/typing.py | 35 +++++++++++++++++++++++------------ tox.ini | 2 -- 3 files changed, 42 insertions(+), 24 deletions(-) diff --git a/python2/typing.py b/python2/typing.py index 9d24306e..b1b3272d 100644 --- a/python2/typing.py +++ b/python2/typing.py @@ -328,13 +328,17 @@ def _type_check(arg, msg): return type(None) if isinstance(arg, basestring): arg = _ForwardRef(arg) - if (isinstance(arg, _TypingBase) and type(arg).__name__ == '_ClassVar' or - not isinstance(arg, (type, _TypingBase)) and not callable(arg)): + if ( + isinstance(arg, _TypingBase) and type(arg).__name__ == '_ClassVar' or + not isinstance(arg, (type, _TypingBase)) and not callable(arg) + ): raise TypeError(msg + " Got %.100r." % (arg,)) # Bare Union etc. are not valid as type arguments - if (type(arg).__name__ in ('_Union', '_Optional') - and not getattr(arg, '__origin__', None) - or isinstance(arg, TypingMeta) and _gorg(arg) in (Generic, _Protocol)): + if ( + type(arg).__name__ in ('_Union', '_Optional') and + not getattr(arg, '__origin__', None) or + isinstance(arg, TypingMeta) and _gorg(arg) in (Generic, _Protocol) + ): raise TypeError("Plain %s is not valid as type argument" % arg) return arg @@ -929,8 +933,10 @@ def _valid_for_check(cls): if cls is Generic: raise TypeError("Class %r cannot be used with class " "or instance checks" % cls) - if (cls.__origin__ is not None and - sys._getframe(3).f_globals['__name__'] not in ['abc', 'functools']): + if ( + cls.__origin__ is not None and + sys._getframe(3).f_globals['__name__'] not in ['abc', 'functools'] + ): raise TypeError("Parameterized generics cannot be used with class " "or instance checks") @@ -1057,9 +1063,12 @@ def __new__(cls, name, bases, namespace, # This allows unparameterized generic collections to be used # with issubclass() and isinstance() in the same way as their # collections.abc counterparts (e.g., isinstance([], Iterable)). - if ('__subclasshook__' not in namespace and extra # allow overriding - or hasattr(self.__subclasshook__, '__name__') and - self.__subclasshook__.__name__ == '__extrahook__'): + if ( + # allow overriding + '__subclasshook__' not in namespace and extra or + hasattr(self.__subclasshook__, '__name__') and + self.__subclasshook__.__name__ == '__extrahook__' + ): self.__subclasshook__ = _make_subclasshook(self) if origin and hasattr(origin, '__qualname__'): # Fix for Python 3.2. diff --git a/src/typing.py b/src/typing.py index bca3a2de..283628c1 100644 --- a/src/typing.py +++ b/src/typing.py @@ -355,13 +355,17 @@ def _type_check(arg, msg): return type(None) if isinstance(arg, str): arg = _ForwardRef(arg) - if (isinstance(arg, _TypingBase) and type(arg).__name__ == '_ClassVar' or - not isinstance(arg, (type, _TypingBase)) and not callable(arg)): + if ( + isinstance(arg, _TypingBase) and type(arg).__name__ == '_ClassVar' or + not isinstance(arg, (type, _TypingBase)) and not callable(arg) + ): raise TypeError(msg + " Got %.100r." % (arg,)) # Bare Union etc. are not valid as type arguments - if (type(arg).__name__ in ('_Union', '_Optional') - and not getattr(arg, '__origin__', None) - or isinstance(arg, TypingMeta) and _gorg(arg) in (Generic, _Protocol)): + if ( + type(arg).__name__ in ('_Union', '_Optional') and + not getattr(arg, '__origin__', None) or + isinstance(arg, TypingMeta) and _gorg(arg) in (Generic, _Protocol) + ): raise TypeError("Plain %s is not valid as type argument" % arg) return arg @@ -850,8 +854,10 @@ def _valid_for_check(cls): if cls is Generic: raise TypeError("Class %r cannot be used with class " "or instance checks" % cls) - if (cls.__origin__ is not None and - sys._getframe(3).f_globals['__name__'] not in ['abc', 'functools']): + if ( + cls.__origin__ is not None and + sys._getframe(3).f_globals['__name__'] not in ['abc', 'functools'] + ): raise TypeError("Parameterized generics cannot be used with class " "or instance checks") @@ -987,9 +993,12 @@ def __new__(cls, name, bases, namespace, # This allows unparameterized generic collections to be used # with issubclass() and isinstance() in the same way as their # collections.abc counterparts (e.g., isinstance([], Iterable)). - if ('__subclasshook__' not in namespace and extra # allow overriding - or hasattr(self.__subclasshook__, '__name__') and - self.__subclasshook__.__name__ == '__extrahook__'): + if ( + # allow overriding + '__subclasshook__' not in namespace and extra or + hasattr(self.__subclasshook__, '__name__') and + self.__subclasshook__.__name__ == '__extrahook__' + ): self.__subclasshook__ = _make_subclasshook(self) if isinstance(extra, abc.ABCMeta): self._abc_registry = extra._abc_registry @@ -1443,10 +1452,12 @@ def get_type_hints(obj, globalns=None, localns=None): hints = getattr(obj, '__annotations__', None) if hints is None: # Return empty annotations for something that _could_ have them. - if (isinstance(obj, types.FunctionType) or + if ( + isinstance(obj, types.FunctionType) or isinstance(obj, types.BuiltinFunctionType) or isinstance(obj, types.MethodType) or - isinstance(obj, types.ModuleType)): + isinstance(obj, types.ModuleType) + ): return {} else: raise TypeError('{!r} is not a module, class, method, ' diff --git a/tox.ini b/tox.ini index 42698b3e..4d9ea4b5 100644 --- a/tox.ini +++ b/tox.ini @@ -15,10 +15,8 @@ ignore = # temporary ignores until we sort it out B007, E128, - E129, E501, E711, - W503, # irrelevant plugins B3, DW12